How to override the doc of an object instance.

Paul McGuire ptmcg at
Wed Jun 21 17:00:00 CEST 2006

"David Huard" <david.huard at> wrote in message
news:mailman.7313.1150898365.27775.python-list at
> On Wed, 21 Jun 2006 15:39:02 +0200, Maric Michaud wrote:
> > This is w.__class__.x.__doc__.
> Thanks,
> So in order to implement what I want, I should rather consider an
> ipython hack to print w.__class__.x.__doc__ when it exists, instead of
> w.x.__doc_ ? Does this makes sense or it will ruin the standard behaviour?
> David
No need to, just assign your special docstrings to w.x.__doc__, and print
w.x.__doc__.  Instances that have special docstrings will print their
instance-specific versions; instances without instance-specific docstrings
will print the class-level version.  See below.

-- Paul

>>> class W(object):
...   "Class-level docstring for W"
...   pass
>>> z = W()
>>> z.__doc__
'Class-level docstring for W'
>>> z.__doc__  = "instance-level docstring, just for z"
>>> z.__doc__
'instance-level docstring, just for z'
>>> zz = W()
>>> print zz.__doc__
Class-level docstring for W
>>> print z.__doc__
instance-level docstring, just for z

More information about the Python-list mailing list