How do I list all the attributes of an object in python pdb?
Question:
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?
Answers:
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.
For pdb, you should be able to do p dir(a)
.
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
print dir(object_name)
will list all the attributes of object for you.
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?
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.
For pdb, you should be able to do p dir(a)
.
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
print dir(object_name)
will list all the attributes of object for you.