I am trying to keep the value of a variable between files on a python script. The end goal is to separate functions from an algorithm.
The function is very simple - I have saved it in a file called test:
def tests(x):
global y
x=10
y=x
return y
Then the algorithm part is again simple - saved in a different file, called test1:
import test as t
y=0
t.tests(y)
print("new value is "+str(y))
However, the value does not seem to be updated to 10 - it keeps its initial value of 0.
I am sure I am missing sth very obvious, but could you pls help?
The above code works if I contain the function and the algorithm parts in the same fie, but I would like to separate them.
Thank you
t.tests(y)to the variable y to update it. Try changing the line toy = t.tests(y)