How do I list all the attributes of an object in python pdb?
Solution 1
For pdb, you should be able to do p dir(a)
.
Solution 2
If a is your object, use dir(a)
to get a list of its symbols. See the documentation about the dir
function for more information.
Solution 3
print dir(object_name)
will list all the attributes of object for you.
Solution 4
pdb is like a python shell, what you can do in pdb is what you can do in Python (except maybe some very exotic stuff)
You can set variables, call functions, ...
dir
is the right function to call. It should work on any objects as it can either default to the builtin or be implemented but I have indeed seen objects on which it fails. I guess it has to do with "old" python code (in my failing case : the suds
library)
Usually __dict__
can be of some help too on the pdb debugger
sorin
Another geek still trying to decipher the meaning of “42”. It seems that amount his main interest are: online communities of practice and the way they evolve in time product design, simplicity in design and accessibility productivity and the way the IT solutions are impacting it
Updated on July 09, 2022Comments
-
sorin almost 2 years
I try to list all the attributes of an object in Python pdb.
Let's say I want to list all the attributes and all methods of
sys.stderr
.How can I do that?
-
sorin over 12 yearsI doesn't work in pdb, it works in python shell, but not in pdb.
-
sorin over 12 yearsIn my case I try to run this on
sys.stdout
and if fails with and exception fromfile
object. -
hochl over 12 yearsboth
print dir(a)
anddir(a)
work in mypdb
. What version of Python are you using? -
sorin over 12 yearsProblem already solved, but I'm using Python 2.5 on Windows. Maybe on newer versions print works by default.
-
hobbes3 about 11 yearsIs there a way to list everything in one column? Kind of like
ls -l
orls -1
in bash. -
vxsx over 9 years@hobbes3 that would be
pp dir(a)
-
AlxVallejo over 6 years@vxsx Don't you need to import pprint for that? docs.python.org/2/library/pprint.html