如何获取 Python 模块的路径?

来源:互联网 发布:机器码生成注册码java 编辑:程序博客网 时间:2024/05/19 22:52
1import a_module
2print a_module.__file__

上述代码将范围 .pyc 文件被加载的路径,如果需要跨平台解决方案,可用下面代码:

1import os
2path =os.path.dirname(amodule.__file__)


转自:http://www.oschina.net/question/149123_25377