On 2020-09-25 7:46 AM, Chris Angelico wrote:
On Fri, Sep 25, 2020 at 3:43 PM Frank Millman <fr...@chagford.com> wrote:
Hi all
I have a problem related (I think) to list comprehension namespaces. I
don't understand it enough to figure out a solution.
In the debugger, I want to examine the contents of the current instance,
so I can type
(Pdb) dir(self)
and get the result with no problem.
However, it is a long list containing attribute names and method names,
and I only want to see the attribute names. So I tried this -
(Pdb) [x for x in dir(self) if not callable(getattr(self, x))]
*** NameError: name 'self' is not defined
(Pdb)
Q1. Can someone explain what is going on?
Q2. Is there a way to get what I want?
If you put that line of code into your actual source code, does it
work? I think this might be a pdb-specific issue, since normally the
comprehension should have no difficulty seeing names from its
surrounding context.
A minimal case will probably involve the debugger and a function with
a local, unless in some way this depends on 'self' being special.
Yes, is does work from within my source code.
Frank
--
https://mail.python.org/mailman/listinfo/python-list