run.py File:
Import M1 # first time importing
# Verify solution One:
‘‘‘
Importing M1
Importing M2
‘‘‘
# Print (m1.x)
# Print (M1.Y)
# Verify solution Two:
Import M1 # first time importing
‘‘‘
Importing M1
‘‘‘
# Print (m1.x)
# Print (M1.F1)
M1.F1 ()
‘‘‘
Importing M2
M1.F1---->Y:M2
M2.F2--->x:m1
‘‘‘
m1.py File:
# Error Demonstration
‘‘‘
print (' importing M1 ')
From m2 Import y # import m2 for the first time
X= ' M1 '
‘‘‘
Solution One: Put the loop-imported statement behind the name definition
Print (' importing M1 ')
x=' M1 '
from M2 import y # first time importing M2
# Solution Two: Put the loop import statement inside the function
Print (' importing M1 ')
def F1 ():
from M2 import y,f2 # first time importing M2
Print (' m1.f1---->y: ', y)
F2 ()
x=' M1 '
m2.py File:
# Error Demonstration
‘‘‘
print (' importing m2 ')
From M1 Import x
Y= ' m2 '
‘‘‘
# Solution One: Put the loop-imported statement behind the name definition
Print (' importing m2 ')
y=' m2 '
from M1 import x
# Solution Two: Put the loop import statement inside the function
Print (' importing m2 ')
def F2 ():
from M1 import x
Print (' m2.f2--->x: ', X)
y=' m2 '
Circular import problem and solution a map
Cyclic import problem and solution two-match diagram
Circular import issues for Python 1-2 modules