how to loop through .py files using importlib

35 Views Asked by At

I am trying to use the prefix modl and iterate through .py files that I use as settings. I'd like to stick to python files because it is easy to declare functions and variables and import them. The problem I run into is that the module does not update at the second iteration:

for settingsfile in ['settings1.py', 'settings2.py']:
    modl = importlib.import_module(settingsfile)
    var1 = modl.var1
    print('the variable:', var1)

output:

the variable:var1_from_settings1
the variable:var1_from_settings1
0

There are 0 best solutions below