如何通過“ import”語句確定在Python中導(dǎo)入了哪個(gè)文件?
想確定正在加載本地修改的.py文件的正確版本。基本上等同于POSIX環(huán)境中的“哪個(gè)”。
解決方案
使用-v參數(shù)啟動(dòng)python 以啟用調(diào)試輸出。當(dāng)您導(dǎo)入模塊時(shí),Python將打印出模塊從以下位置導(dǎo)入的位置:

$ 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在其他什么地方搜索了該模塊,請(qǐng)?zhí)砑拥诙€(gè)-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 ...