How to retrieve a module's path?

后端 未结 20 1777
无人及你
无人及你 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:11

    When you import a module, yo have access to plenty of information. Check out dir(a_module). As for the path, there is a dunder for that: a_module.__path__. You can also just print the module itself.

    >>> import a_module
    >>> print(dir(a_module))
    ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
    >>> print(a_module.__path__)
    ['/.../.../a_module']
    >>> print(a_module)
    
    

提交回复
热议问题