Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 模块';测试';没有属性';变量';_Python_Global Variables_Spyder - Fatal编程技术网

Python 模块';测试';没有属性';变量';

Python 模块';测试';没有属性';变量';,python,global-variables,spyder,Python,Global Variables,Spyder,我有两个文件: testons.py(一个空文件) test_main.py: import testons print(testons.gamma) 我使用spyder run按钮运行test_main.py,该按钮返回错误“模块'testons'没有属性'gamma'”(这很正常,我没有定义此变量) 然后在spyder内部的Python控制台中执行:testons.gamma=2 我正确地说: print(testons.gamma) # It returns me 2 as expec

我有两个文件:

testons.py(一个空文件)

test_main.py:

import testons

print(testons.gamma)
我使用spyder run按钮运行test_main.py,该按钮返回错误“模块'testons'没有属性'gamma'”(这很正常,我没有定义此变量)

然后在spyder内部的Python控制台中执行:testons.gamma=2

我正确地说:

print(testons.gamma) # It returns me 2 as expected.
但是,如果在使用spyder的run按钮重新运行test_main.py之后,仍然会得到相同的错误


为什么会这样?现在应该定义我的变量了!一切都像python清除了我的变量一样…?

如何运行test\u main.py?你说的“python控制台”是什么意思?@John Gordon我用spyder软件中的run按钮运行它。我说的是spyder的python控制台。也许我的问题与软件有关?我怀疑从Spyder单击“运行”按钮会启动一个新的上下文,它不记得您之前对
testons.gamma
所做的修改。您是如何运行test\u main.py的?你说的“python控制台”是什么意思?@John Gordon我用spyder软件中的run按钮运行它。我说的是spyder的python控制台。也许我的问题与软件有关?我怀疑从Spyder单击“运行”按钮会启动一个新的上下文,并且它不记得您之前对
testons.gamma所做的修改。