46

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?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
sorin
  • 161,544
  • 178
  • 535
  • 806

4 Answers4

68

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

sorin
  • 161,544
  • 178
  • 535
  • 806
Dan Breen
  • 12,626
  • 4
  • 38
  • 49
9

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.

hochl
  • 12,524
  • 10
  • 53
  • 87
  • 1
    both `print dir(a)` and `dir(a)` work in *my* `pdb`. What version of Python are you using? – hochl Oct 27 '11 at 10:57
  • Problem already solved, but I'm using Python 2.5 on Windows. Maybe on newer versions print works by default. – sorin Oct 27 '11 at 11:37
7

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

Aamish Baloch
  • 1,200
  • 12
  • 9
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

Thomas
  • 8,306
  • 8
  • 53
  • 92