我无法在 Spyder 4.0.0 中与 Python 3.8、Windows 10 交互地修改全局变量。最近一定有更改,因为这以前是可能的。
我有以下示例文件:
x = 5
def IncreaseX():
global x
x += 1
print(x)
IncreaseX()
print(x)
Run Code Online (Sandbox Code Playgroud)
In [1]: runfile('TestGlobals.py', wdir='D:')
5
6
Run Code Online (Sandbox Code Playgroud)
In [2]: x
Out[2]: 6
In [3]: IncreaseX()
In [4]: x
Out[4]: 6
Run Code Online (Sandbox Code Playgroud)
In [5]: print(x)
...: IncreaseX()
...: print(x)
6
6
Run Code Online (Sandbox Code Playgroud)
In [6]: x = 5
...: def IncreaseX():
...: global x
...: x += 1
...:
...: …Run Code Online (Sandbox Code Playgroud)