How to retrieve a module's path?

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

    If you want to retrieve the package's root path from any of its modules, the following works (tested on Python 3.6):

    from . import __path__ as ROOT_PATH
    print(ROOT_PATH)
    

    The main __init__.py path can also be referenced by using __file__ instead.

    Hope this helps!

提交回复
热议问题