В file1.py:ошибка импорта в Python
def test1():
print "hi"
В file2.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
Может кто-нибудь объяснить, почему и как заставить его работать?
Предварительный просмотр перед отправкой. Это было довольно непроницаемо. – 2010-12-08 12:41:54
циклический импорт, прочитайте все об этом. – SilentGhost 2010-12-08 12:43:14