本文介绍了如何获取模块的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检测模块是否已更改.现在,使用inotify很简单,您只需要知道要从中获取通知的目录即可.
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.
如何在python中检索模块的路径?
How do I retrieve a module's path in python?
推荐答案
import a_module
print(a_module.__file__)
实际上,至少在Mac OS X上,将为您提供已加载的.pyc文件的路径.所以我想您可以这样做:
Will actually give you the path to the .pyc file that was loaded, at least on Mac OS X. So I guess you can do:
import os
path = os.path.abspath(a_module.__file__)
您也可以尝试:
path = os.path.dirname(a_module.__file__)
获取模块的目录.
这篇关于如何获取模块的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!