赞
踩
今天用到嵌套import的时候发现一个问题。请看下面:
看上面的test1的包,下面是各个源文件的内容:
#a.py
def p():
print("12345")
#b.py
import a
#from . import a
def bi():
a.p()
#c.py
from .src import b
def yi():
print("wo")
b.bi()
#d.py
# import sys
# sys.path.append('./py/src')
import py.c
if __name__ == '__main__':
py.c.yi()
这里运行d.py就会报错:
/home/andy/anaconda3/bin/python /home/andy/work/mypython/test/test1/d.py
Traceback (most recent call last):
File "/home/andy/work/mypython/test/test1/d.py", line 3, in <module>
import py.c
File "/home/andy/work/mypython/test/test1/py/c.py", line 2, in <module>
from .src import b
File "/home/andy/work/mypython/test/test1/py/src/b.py", line 2
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。