为什么我无法在 pdb 中访问 self.<method>

问题描述

考虑这样的代码片段:

class ABC:
    def method1(self,word):
             ...

    def method2(self):
        str_list = ['this','is','a','list','of','strings']
        pdb.set_trace()
        str_list = [self.method1(word) for word in str_list] ...(1)

obj = ABC()
obj.method2()

在断点处,当我在 pdb 调试器 shell 中复制粘贴命令 (1) 时,它无法执行该命令,而是给了我错误:

*** NameError: name 'self' is not defined

谁能帮我理解这种行为 - 是否与列表推导式和类对象的范围有关?


PS C:\fooProjects> & C:/Python38/python.exe c:/fooProjects/tmp.py
> c:\fooprojects\tmp.py(38)method2()
-> str_list = [self.method1(word) for word in str_list]
(Pdb) [self.method1(word) for word in str_list]
*** NameError: name 'self' is not defined
(Pdb)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)