Yes: I know that we shouldn't be using global variables in Python but I'm trying to understand this behavior.
I have this file called bug.py :
x = 0
def foo():
global x
x = 100
if __name__ == '__main__':
foo()
print(x)
when I execute this as a file I get the expected result of a 100, see below.
(mani) franz@ubuntu:~/dropboxpython/poolparty$ python bug.py
100
However, when I do the same thing in the repl, x doesn't turn 100, see below
(mani) franz@ubuntu:~/dropboxpython/poolparty$ python
Python 3.6.4 | packaged by conda-forge | (default, Dec 23 2017, 16:31:06)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from bug import *
>>> x
0
>>> foo()
>>> x
0
Why does this happen?