In ipython I am using %run to execute the following code from a file:
foo = 32
def test7():
global foo
print("foo before:", foo)
foo += 1
print("foo after:", foo)
My ipython transcript goes as follows:
$ ipython
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) ...
In [1]: %run "a1.py"
In [2]: foo
Out[2]: 32
In [3]: test7()
foo before: 32
foo after: 33
In [4]: foo
Out[4]: 32
In [5]: test7()
foo before: 33
foo after: 34
In [6]: foo
Out[6]: 32
In [7]:
My question is: why does querying the value of foo within ipython always return 32 when the test7() routine seems to be incrementing it?
And is there a way I can see the same value of foo that the test7() function is seeing?
print(foo) test7() print(foo) test7() print(foo)(All are in new lines)