I have 3 files: main, calc, and settings organized like this:
# main.py
import settings as s
import calc as c
class Main:
def __init__(self):
calc = c.Calc()
self.my_var = user_input
s.changing_variable = self.my_var
def run(self):
calc.do_something()
# calc.py
import settings as s
class Calc:
def __init__(self):
self.test_variable = s.changing_variable
# settings.py
changing_variable = original_value
All code is run from the main file. I have an original value in the settings file that I now want to change based on the user input in my main file. This value should then be changed globally for all files.
The problem is that it is changed for the main file but not for the calc file. I assume this is because I import settings at the beginning of calc.py and therefore override the user input again.
Does anyone have any idea how to solve this without having to pass the user input variable around in the function calls?