'AttributeError: module ' ' has no attribute ' '

I have 2 python files where I want to import from each to the other, however I get this error AttributeError: module 'b' has no attribute 'y'. I have already imported file a in file b and everything works. I want to access variable y from file b in file a but when I import file b in file a, I get this AttributeError which I know is from the circular imports. Is there any way I can access y variable from file b in file a after already importing file a in file b. Any suggestions are welcomed. Thanks in Advance. Below is a sample code for demonstration.

file b.py

import a
y = x + 2

file a.py

import b
for i in range(5):
     if b.y == 1:
        do_something()
     else:
        return


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source