[Tutor] nested / concatenated function docstrings?

Alan Gauld alan.gauld at btinternet.com
Fri May 27 02:19:46 CEST 2011


"Prasad, Ramit" <ramit.prasad at jpmchase.com> wrote

> I would like to have the docstring for function first also 
> contain the docstring for second because it should 
> support/pass any argument second contains. 

You can explicitly set the docstring by assigning to __doc__:


>>> def f():
...  '''here is f's doc string '''
...  return 42
... 
>>> def g():
...  return f() + 10
... 
>>> g.__doc__ = "Here is g's help\n" + f.__doc__
>>> help(g)
>>> help(g)
Help on function g in module __main__:

g()
    Here is g's help 
    here is f's doc string

>>>

There may be a more elegant way but that seems to work...


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list