How to retrieve a module's path?

后端 未结 20 1768
无人及你
无人及你 2020-11-22 05:34

I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.

How do I retrieve

20条回答
  •  长发绾君心
    2020-11-22 06:24

    Command Line Utility

    You can tweak it to a command line utility,

    python-which 
    


    Create /usr/local/bin/python-which

    #!/usr/bin/env python
    
    import importlib
    import os
    import sys
    
    args = sys.argv[1:]
    if len(args) > 0:
        module = importlib.import_module(args[0])
        print os.path.dirname(module.__file__)
    

    Make it executable

    sudo chmod +x /usr/local/bin/python-which
    

提交回复
热议问题