I have a simlair problem as in this question: AttributeError: 'module' object has no attribute
I’m doing a mutual top level import which is causing me to have AttributeError: ‘module’ object has no attribute error so but I’m not sure if I can import within a function because I’m basically importing a file that controls all the other modules.
Here’s an example(file2.py):
import file1
count = 0
while count < file1.number_of_loops:
.....
My functions are being triggered by the control variables so I’m unable to import within the function itself. Short of creating a sperate file to control, is there a way to refer to variables in another file without doing a mutual top level import?
As pointed out by a comment, if you’re using
file1.pyto store some configuration variables, then it would be better to have a look at alternative ways of dealing with that configuration.In my opinion, a simple way to address your problem would be to move all those variables to another module called, for example,
settings.pyso that you can get the configuration from there without having to use any mutual import.