[英]Does import __foo__ import from the __init__ file of the foo package?
I've been reading some code that used the following import statement: 我一直在阅读一些使用以下导入语句的代码:
import __ompc__
When I tried to grep to find just what was being imported, all I found was: 当我尝试grep查找正在导入的内容时,我发现的是:
me@Bedrock1:~/Projects/PythonProjects/ompc$ grep -r "__ompc__" ./*
./build/lib.linux-x86_64-2.7/ompclib/m_compile.py:import __ompc__
./build/lib.linux-x86_64-2.7/ompclib/m_compile.py: codeobject = __ompc__.compile(codestring, dfile or file,'exec')
./build/bdist.linux-x86_64/egg/ompclib/m_compile.py:import __ompc__
./build/bdist.linux-x86_64/egg/ompclib/m_compile.py: codeobject = __ompc__.compile(codestring, dfile or file,'exec')
Binary file ./build/bdist.linux-x86_64/egg/ompclib/m_compile.pyc matches
./ompclib/m_compile.py:import __ompc__
./ompclib/m_compile.py: codeobject = __ompc__.compile(codestring, dfile or file,'exec')
Since __ompc__
was used to find a method named ' compile
', I did a recursive grep on that. 由于使用
__ompc__
来查找名为“ compile
”的方法,因此我对此进行了递归grep。 What I found was the __init__.py
file in the ./ompc/ompc
directory had a compile method. 我发现在
./ompc/ompc
目录中的__init__.py
文件有一个编译方法。
Is this what 这是什么
import __ompc__
gives access to? 可以访问? Or is there still something going on here that I don't understand?
还是这里发生了我不理解的事情?
I cannot actually make ompclib/m_compile.py
work . 我实际上无法使
ompclib/m_compile.py
工作 。 ompc/m_compile.py
is almost the same file, but is actually used by the ompc
codebase. ompc/m_compile.py
几乎是同一文件,但ompc
代码库实际上使用了ompc
。
My conclusion is that that file and probably the whole ompclib
directory is a left-over from an earlier development stage and the author simply has forgotten to clean it up. 我的结论是,该文件以及整个
ompclib
目录可能是早期开发阶段的遗留物,而作者只是忘了清理它。
The import __ompc__
import is otherwise nothing more but a broken import. import __ompc__
导入只不过是一个损坏的导入。 It does not magically transform into importing the ompc
package. 它不会神奇地转变为导入
ompc
包。 ompc/m_compile.py
does work, and uses import ompc
instead. ompc/m_compile.py
确实可以使用,而是使用import ompc
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.