Consider a code snippet like this:
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()
At the break point, when I copy-paste the command (1) in the pdb debugger shell, it fails to execute the command and rather gives me the error:
*** NameError: name 'self' is not defined
Can anyone help me understand this behavior - is it something related to the scope of list comprehensions and class objects?
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)