Python - NameError:未定义全局名称“plus”

Python - NameError:未定义全局名称“plus”

我正在使用 shelve 创建一个程序,但一直收到此错误消息。我无论如何也想不通,谷歌也没有提供太多帮助。这是 Ubuntu/Python 协同工作的问题,还是我的程序出了问题?

'plus' 是我的搁置文件的名称,我正尝试打开一个新的搁置文件进行写入。

这是我的 IDLE 控制台死机时的屏幕:

Traceback (most recent call last):
File "/media/Windows-XP-Pro/Python32/Scripts/plu.py", line 217, in <module> start()
File "/media/Windows-XP-Pro/Python32/Scripts/plu.py", line 147, in start end() # Go to the end() definition
File "/media/Windows-XP-Pro/Python32/Scripts/plu.py", line 110, in end dPLU = shelve.open(plus)
NameError: global name 'plus' is not defined

任何帮助,将不胜感激

答案1

如果文件的名称是“plus”,那么该行应该是:

dPLU = shelve.open('plus')

换句话说,需要传入一个字符串,但看起来好像传入了一个变量(尚未定义)。

相关内容