获取 python import模块的路径

import a_module
print a_module.__file__


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

import os
path = os.path.dirname(amodule.__file__)
原文地址:https://www.cnblogs.com/qiumingcheng/p/7760215.html