tags:

views:

86

answers:

6

So, I know I can use dir() to get information about class members etc. What I'm looking for is a way to get a nicely formatted report on everything related to a class (the members, docstrings, inheritance hierarchy, etc.).

I want to be able to run this on the command-line so I can explore code and debug better.

+5  A: 

Try calling help on your class.

Mike Graham
Also, write docstrings for your class, that makes the help look even better.
S.Lott
Exactly what I wanted. Thanks!
+4  A: 

Try this from the command line:

pydoc modulename
Nadia Alramli
A: 

Not sure exactly what you need, but this chapter from Mark Pilgrim's "Dive into Python" might work.

EDIT: Cleared up formatting.

Jonathanb
A: 

try ipython

gnibbler
+1  A: 

Try the help() facility that is built into the interpreter. E.g.

class X(object):
    """Docstring for an example class."""
    def __init__(self):
        """Docstring for X.__init__()."""
        pass
    def method1(self, x):
        """Docstring for method1()."""
        print x

>>> help(X)
Help on class X in module __main__:

class X(__builtin__.object)
 |  Docstring for an example class.
 |  
 |  Methods defined here:
 |  
 |  __init__(self)
 |      Docstring for X.__init__().
 |  
 |  method1(self, x)
 |      Docstring for method1().
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  __dict__ = <dictproxy object>
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__ = <attribute '__weakref__' of 'X' objects>
 |      list of weak references to the object (if defined)

This works for just about anything, e.g.

>>> help(dir):
Help on built-in function dir in module __builtin__:

dir(...)
    dir([object]) -> list of strings

    Return an alphabetized list of names comprising (some of) the attributes
    of the given object, and of attributes reachable from it:

    No argument:  the names in the current scope.
    Module object:  the module attributes.
    Type or class object:  its attributes, and recursively the attributes of
        its bases.
    Otherwise:  its attributes, its class's attributes, and recursively the
        attributes of its class's base classes.
mhawke
A: 

You want introspection. This is a good article about all that: http://www.ibm.com/developerworks/library/l-pyint.html

On the other hand, for debugging, you might just want to use Eclipse with the Python plugin.

Gyuri