我正在从程序本身的某个程序中导入一个模块。
我可以运行Python命令,我需要我正在导入的python模块的路径。
该模块不包含__file__
属性,这似乎是主要方式。
使用sys.modules[<module>]
返回<module (built-in)>
有解决方法吗?
答案 0 :(得分:1)
您可以尝试使用 inspect
提供的getfile()
方法。
import inspect
inspect.getfile(inspect) # returns '/usr/lib/python2.7/inspect.pyc'