Python 2.7 ex 25 LPTHW(未定义全局名称pop)

Python 2.7 ex 25 LPTHW(未定义全局名称pop),python-2.7,Python 2.7,我目前正在学习如何使用python编写代码,这是在“艰苦学习python”网站上进行的练习 问题是我无法完成练习25,因为我有一个我无法解决的问题 我正在python控制台中键入,但在指令编号8ex25处。打印最后一个单词我有以下错误: >>> ex25.print_last_word(words) Traceback (most recent call last): File "<stdin>", line 1, in <module> Fil

我目前正在学习如何使用python编写代码,这是在“艰苦学习python”网站上进行的练习

问题是我无法完成练习25,因为我有一个我无法解决的问题

我正在python控制台中键入,但在指令编号8
ex25处。打印最后一个单词
我有以下错误:

>>> ex25.print_last_word(words)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ex25.py", line 19, in print_last_word
    word = words.pop(-1)
NameError: global name 'POP' is not defined

Python解释器引发的错误与您发布的代码不匹配,因为您的代码中从未提到过
POP

该错误可能表示解释器内存中模块
ex25
的定义与文本文件
ex25.py
中的定义不同。你可以使用

请注意,每次修改
ex25.py
时都必须执行此操作


因此,您可能会发现更容易修改
ex25.py
,以便通过添加

if __name__ == '__main__':
    words = ...
    print_last_word(words)
ex25.py
的末尾,并从命令行运行脚本:

python ex25.py

非常感谢你!!我认为我还没有完全理解这个问题,但我认为我会在将来努力解决这个问题。
if __name__ == '__main__':
    words = ...
    print_last_word(words)
python ex25.py