我对导入的工作方式有点困惑。认为:
package/
__init__.py
file1.py
在__init__.py
:
from file1 import AClass
__version__ = '1.0'
在file1.py
:
Class AClass(object):
def bar():
# I want to use __version__here, but don't want to pass
# it through the constructor. Is there any way?
pass
如果我使用from . import __version__
它file1.py
只是说ImportError: cannot import name __version__
。