I though it was easy, but I just can't do it. I read in the doc that this should work :
a/__init__.py
#nothing here
a/b.py
var = "hello world"
a/c.py
import b
print(b.var)
From .
:
>>> import a.c
ImportError: No module named 'b'
But it does not… What have I forgotten ? Is it because I use Python 3 ?
yes, it's because of Python3.
In Python 3, implicit relative imports within packages are no longer available
没关系,我相信您应该将文件保存在Program Files(x86)/ Lib中以创建一个新模块,适用于Python 2.7.6,但是很有可能也适用于Python 3.0。
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.