doc string substition and overloading __doc__

Steven Taschuk staschuk at telusplanet.net
Fri May 2 20:16:21 EDT 2003


Quoth Fernando Perez:
  [...]
> Note that, in a quirk of counter-intuitiveness, the following code is
> accepted but the assignment fails silently.  This one I'd call a wart, at
> least:
> 
> In [5]: def def3():
>    ...:     def3.__doc__ = 'hi'
>    ...:
> 
> In [6]: pdoc def3
> No documentation found for def3

The assignment doesn't fail, silently or otherwise; it just isn't
run until the function is called, like any statement in a function
body.

    >>> def foo():
    ...     foo.__doc__ = 'Bar!'
    ... 
    >>> foo.__doc__
    >>> foo()
    >>> foo.__doc__
    'Bar!'

-- 
Steven Taschuk                                                 o- @
staschuk at telusplanet.net                                      7O   )
                                                               "  (





More information about the Python-list mailing list