比如我有个叫test.py的脚本,我再它的内部调用import test 但test模块确实存在于site-packages中。在windows中这会默认引用的是test.py==有办法解决嘛

1 dreampuf Aug 13, 2014 - 尽量避开重名模块 - 从项目路径导入 from YOURAPP import test - 改变 sys.path 顺序 |
2 Zuckonit Aug 13, 2014 名字没取好 可以加上路径 |
3 pyKun Aug 13, 2014 以后不要取这种命 除了一楼的方法还有 import ..test 类的写法 |
4 timonwong Aug 13, 2014 还有更猥琐的方法 import imp mod = imp.load_source(module_name, fullpath) |
5 datou552211 OP |
6 dreampuf Aug 13, 2014 @datou552211 print(module.__file__) 事半功倍 |