sorin
sorin

Reputation: 170658

How do I list all the attributes of an object in python pdb?

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?

Upvotes: 49

Views: 61321

Answers (4)

Aamish Baloch
Aamish Baloch

Reputation: 1200

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

Upvotes: 7

Thomas
Thomas

Reputation: 8968

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

Upvotes: 4

Dan Breen
Dan Breen

Reputation: 12934

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

Upvotes: 72

hochl
hochl

Reputation: 12950

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.

Upvotes: 10

Related Questions