比如我有个叫test.py的脚本,我再它的内部调用import test 但test模块确实存在于site-packages中。在windows中这会默认引用的是test.py==有办法解决嘛
|
dreampufAug 13, 2014
1
- 尽量避开重名模块
- 从项目路径导入 from YOURAPP import test - 改变 sys.path 顺序 |
|
ZuckonitAug 13, 2014
2
名字没取好
可以加上路径 |
|
pyKunAug 13, 2014
3
以后不要取这种命
除了一楼的方法还有 import ..test 类的写法 |
|
4
还有更猥琐的方法
import imp mod = imp.load_source(module_name, fullpath) |
|
5
|
|
dreampufAug 13, 2014
6
@datou552211 print(module.__file__) 事半功倍
|