获取 Python 模块的路径

import a_module
print a_module.__file__

如果需要跨平台,可用下面代码:

#!/usr/bin/env python
#coding:utf-8
import os
path = os.path.dirname(amodule.__file__)

作者:@烈风
出处:http://www.cnblogs.com/ipython/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/ipython/p/3382981.html