[IPython-user] Printing the doc of the class object instead of the object instance

David Huard david.huard at gmail.com
Wed Jun 21 09:48:14 CDT 2006


Hi,

I'm coding a class with attributes where the __set__ method is overloaded
using property, and it annoys me that the docstring printed is the string
from the instance instead of the string from the class, as it is not very
useful in my context. 

For example, if we define

class widget (object):
    """This is a widget."""
    def  __init__(self):
        self._x = None
    def fget(self):
        return self._x
    def fset(self, value):
        self._x = value
        print self._x, 'Ok'
    x = property(fget = fget, fset = fset, doc= "Set x to an int between
     2 and 4")

and call 
w = widget()
w.x = 5
w.x?
will print the docstring of an int. Is it possible for ipython to print 
w.__class__.x.__doc__ instead ?

Thanks, 

David Huard






More information about the IPython-user mailing list