Reputation: 19
#app.py
print('ran')
from model import func2
print('Imported')
def func1():
pass
print('func defined')
func2()
#model.py
def func2():
pass
from app import func1
func1()
python app.py
ran
ran
Imported
func defined
Imported
func defined
python model.py
ran
Traceback (most recent call last):
File "C:/Users/AFAM RK/PycharmProjects/deepdive/test/model.py", line 3, in <module>
from app import func1
File "C:\Users\AFAM RK\PycharmProjects\deepdive\test\app.py", line 2, in <module>
from model import func2
File "C:\Users\AFAM RK\PycharmProjects\deepdive\test\model.py", line 3, in <module>
from app import func1
ImportError: cannot import name 'func1' from partially initialized module 'app' (most likely due to a circular import) (C:\Users\AFAM RK\PycharmProjects\deepdive\test\app.py)
app.py run without any error, but while running model.py i get circular import error.
why its happening?
why its not raise error while running app.py?
Upvotes: 0
Views: 48
Reputation: 461
If you run python app.py the interpeter
Now if you run python model.py the interpreter
Upvotes: 1