在 file1.py 中:
def test1():
print "hi"
在文件 2.py 中:
from file1 import test1
def test2():
print "hello"
test1()
test2()
输出:
hi
hello
现在在文件 1 中,如果我包含 test2,我会收到以下错误:
from file2 import test2
def test1():
print "hi"
Traceback (most recent call last):
File "file1.py", line 1, in ?
from file2 import test2
File "/root/pyt/file2.py", line 1, in ?
from file1 import test1
File "/root/pyt/file1.py", line 1, in ?
from file2 import test2
ImportError: cannot import name test2
有人可以解释为什么以及如何使其工作吗?