Python - 导入全局/ site-packages模块,而不是本地目录中相同名称的文件 [英] Python - Importing a global/site-packages module rather than the file of the same name in the local directory
问题描述
test_utils.py
。如果我去 import test_utils
,那么它将导入这个本地文件。 是否可以让python使用非本地/非相对/全局导入?我想我可以重命名我的 test_utils.py
,但我很好奇。
由于我的 test_utils
在django项目中,我可以从..test_utils import ... 导入全局。
I'm using python and virtualenv/pip. I have a module installed via pip called test_utils
(it's django-test-utils). Inside one of my django apps, I want to import that module. However I also have another file test_utils.py
in the same directory. If I go import test_utils
, then it will import this local file.
Is it possible to make python use a non-local / non-relative / global import? I suppose I can just rename my test_utils.py
, but I'm curious.
Since my test_utils
was in a django project, I was able to go from ..test_utils import ...
to import the global one.
这篇关于Python - 导入全局/ site-packages模块,而不是本地目录中相同名称的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!