您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

列出来自Python调试器的理解范围错误

列出来自Python调试器的理解范围错误

在Python 3中,interact由于实现理解的方式发生了变化,因此必须先在pdb中使用命令才能访问任何非全局变量

>>> def foo(): [][0]
... 
>>> foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in foo
IndexError: list index out of range
>>> import pdb;pdb.pm()
> <stdin>(1)foo()
(Pdb) x = 4
(Pdb) [x for _ in range(2)]
*** NameError: name 'x' is not defined
(Pdb) interact
*interactive*
>>> [x for _ in range(2)]
[4, 4]
>>>
python 2022/1/1 18:28:22 有177人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶