如何通过“ import”语句确定在Python中导入了哪个文件?
想确定正在加载本地修改的.py文件的正确版本。基本上等同于POSIX环境中的“哪个”。
使用-v参数启动python 以启用调试输出。当您导入模块时,Python将打印出模块从以下位置导入的位置:
$ python -v ... >>> import re # /usr/lib/python2.6/re.pyc matches /usr/lib/python2.6/re.py import re # precompiled from /usr/lib/python2.6/re.pyc ...
如果您还想查看Python在其他什么地方搜索了该模块,请添加第二个-v:
$ python -v -v ... >>> import re # trying re.so # trying remodule.so # trying re.py # trying re.pyc # trying /usr/lib/python2.6/re.so # trying /usr/lib/python2.6/remodule.so # trying /usr/lib/python2.6/re.py # /usr/lib/python2.6/re.pyc matches /usr/lib/python2.6/re.py import re # precompiled from /usr/lib/python2.6/re.pyc ...