What will happen if two modules import each other?
To generalize the problem, what about the cyclic imports in Python?
I solved the problem the following way, and it works well without any error.
Consider two files a.py
and b.py
.
I added this to a.py
and it worked.
if __name__ == "__main__":
main ()
import b
y = 2
def main():
print ("a out")
print (b.x)
if __name__ == "__main__":
main ()
import a
print ("b out")
x = 3 + a.y
The output I get is
>>> b out
>>> a out
>>> 5