How to retrieve a module's path?

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

    This was trivial.

    Each module has a __file__ variable that shows its relative path from where you are right now.

    Therefore, getting a directory for the module to notify it is simple as:

    os.path.dirname(__file__)
    

提交回复
热议问题