Say I have three files like this:
testimports module:
#import moduleTwo
import moduleOne
hiString = "Hi!"
moduleOne.sayHi()
moduleOne:
import moduleTwo
class sayHi():
moduleTwo.printHi()
moduleTwo:
import testimports
def printHi():
print(testimports.hiString)
If I run testimports
, I get the following:
Traceback (most recent call last):
File "..file path snipped../testimports/src/testimports.py", line 2, in <module>
import moduleOne
File "..file path snipped../testimports/src/moduleOne.py", line 1, in <module>
import moduleTwo
File "..file path snipped../testimports/src/moduleTwo.py", line 1, in <module>
import testimports
File "..file path snipped../testimports/src/testimports.py", line 6, in <module>
moduleOne.sayHi()
AttributeError: 'module' object has no attribute 'sayHi'
If, however, I uncomment the import moduleTwo
line in testimports
, the program gets to this point before it stops working:
Traceback (most recent call last):
File "..file path snipped../testimports/src/testimports.py", line 1, in <module>
import moduleTwo
File "..file path snipped../testimports/src/moduleTwo.py", line 1, in <module>
import testimports
File "..file path snipped../testimports/src/testimports.py", line 2, in <module>
import moduleOne
File "..file path snipped../testimports/src/moduleOne.py", line 3, in <module>
class sayHi():
File "..file path snipped../testimports/src/moduleOne.py", line 4, in sayHi
moduleTwo.printHi()
AttributeError: 'module' object has no attribute 'printHi'
How would I go about resolving this circular dependency problem?