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?

Asked By: sorin

||

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.

Answered By: hochl

For pdb, you should be able to do p dir(a).

Answered By: Dan Breen

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

Answered By: Thomas

print dir(object_name) will list all the attributes of object for you.

Answered By: Aamish Baloch
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.