the global keyword:
Marcin Rak
mrak at sightlineinnovation.com
Sat Jun 11 19:44:32 EDT 2016
Hi to all.
I have the following file named Solver.py:
*****************************************
from Test import some_function, my_print
from Test import test_var
some_function()
my_print()
print(test_var)
*****************************************
and I have the following Test.py:
*****************************************
test_var = 5
def some_function():
global test_var
test_var = 44
print("f {0}".format(test_var))
def my_print():
print(test_var)
*****************************************
Would you believe it that when I run Solver.py I get the following output:
f 44
44
5
So my question is, how the heck is it possible that I get 5 as the last value printed? the global test_var (global to Test.py) I set to 44 when I ran some_function()??? does anyone have a clue they could throw my way?
Much thanks
More information about the Python-list
mailing list