So, I have:
file_1.py
variable_one = 20
and I also have:
file_2.py
class class_2():
def do_something_2(self):
...
from file_1 import variable_one
variable_one = 100
print("variable_one = ", variable_one) # 100
...
and that:
file_3.py
class class_3():
def do_something_3(self):
...
from file_2 import variable_one
print("variable_one = ", variable_one) # 20
...
The problem is that although file_2.py
changes the variable_one
, in the file_3.py
I don't get the number 100 but the number 20. variable_one
in
file_1.py
is defined as global
. I have tried a recently opened thread, which works for what I asked there but the current problem is a bit different in the current thread (here: Cannot access global variable inside a parent class (python)). I have also tried this suggestion: Working with global variables in multiple classes and multiple modules and I got this:
AttributeError: module 'class_2' has no attribute 'variable_one'
Any idea how to read the correct (modified global variable in file_2.py) from class_3 ???