I am trying to understanding cyclic import problem, Here I have three python files,
py1.py
import py3
py3.test3()
def test1():
print 'test 1'
py2.py
import py1
py1.test1()
def test2():
print 'test 2'
py3.py
import py2
py2.test2()
def test3():
print 'test 2'
when I run the python py3.py
and got the error like this,
Traceback (most recent call last):
File "py3.py", line 1, in <module>
import py2
File "/home/me/Desktop/hackerearth/cylic/py2.py", line 1, in <module>
import py1
File "/home/me/Desktop/hackerearth/cylic/py1.py", line 1, in <module>
import py3
File "/home/me/Desktop/hackerearth/cylic/py3.py", line 3, in <module>
py2.test2()
AttributeError: 'module' object has no attribute 'test2'
But when I remove the import py3
from py1.py file I got the output without any errors. Any one explain me why I am got this error.