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

46,063

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

Share:
46,063
sorin
Author by

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, 2022

Comments

  • sorin
    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
    sorin over 12 years
    I doesn't work in pdb, it works in python shell, but not in pdb.
  • sorin
    sorin over 12 years
    In my case I try to run this on sys.stdout and if fails with and exception from file object.
  • hochl
    hochl over 12 years
    both print dir(a) and dir(a) work in my pdb. What version of Python are you using?
  • sorin
    sorin over 12 years
    Problem already solved, but I'm using Python 2.5 on Windows. Maybe on newer versions print works by default.
  • hobbes3
    hobbes3 about 11 years
    Is there a way to list everything in one column? Kind of like ls -l or ls -1 in bash.
  • vxsx
    vxsx over 9 years
    @hobbes3 that would be pp dir(a)
  • AlxVallejo
    AlxVallejo over 6 years
    @vxsx Don't you need to import pprint for that? docs.python.org/2/library/pprint.html