简体   繁体   中英

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:

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. What I found was the __init__.py file in the ./ompc/ompc directory had a compile method.

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 . ompc/m_compile.py is almost the same file, but is actually used by the ompc codebase.

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.

The import __ompc__ import is otherwise nothing more but a broken import. It does not magically transform into importing the ompc package. ompc/m_compile.py does work, and uses import ompc instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM