I am new to python and trying to update a variable, say x, in an imported module and then trying to use the updated variable x in other variable, say y, but y uses the old value of x instead of the new value. Please help provide some pointers to make it work!
My intention is to use a py file to list all global variable which I can use them in other py files. I could update a global variable and use it but not sure how to use an updated global variable in other variables.
Sample code:
a.py:
var1 = 0
var2 = var1 + 1
b.py:
import a
def update_var():
a.var1 = 10
print("Updated var1 is {}".format(a.var1))
print("var2 is {}".format(a.var2))
if __name__ == "__main__":
update_var()
Output:
Updated var1 is 10
var2 is 1
Expected Output:
Since i am updating var1 to 10, i am expecting that the updated value be used in var2
Updated var1 is 10
var2 is 11