docstrings

Christian Tismer tismer at tismer.com
Fri Apr 21 15:20:08 EDT 2000


Ben Wolfson wrote:
> 
> On 20 Apr 2000 16:22:49 GMT, mjackson at wc.eso.mc.xerox.com (Mark
> Jackson) wrote:
> 
> >Ben Wolfson <rumjuggler at home.com> writes:
> >> is there a way to use %c and %s within a docstring, or to add strings
> >> together in a docstring, so that if some strings are used in all
> >> docstrings, but might be changed, I can simply change one or two
> >> variables?
> >
> >This might do what you want, although it's ugly (in the sense that it
> >serves the code-documentation - as opposed to user-documentation -
> >function less well):
> >
> >    cat > spam.py
> >    """I am a docstring"""
> >
> >    sharedoc = """ and I am a widely-reused docstring clause"""
> >
> >    __doc__ = __doc__ + sharedoc
> >
> >    del sharedoc
> >    ^D
> >    yngvi> python
> >    Python 1.5.2 (#7, May  6 1999, 14:39:45)  [GCC 2.8.1] on sunos5
> >    Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >    >>> import spam
> >    >>> print spam.__doc__
> >    I am a docstring and I am a widely-reused docstring clause
> >    >>>
> 
> This approach doesn't work for function docstrings, unless I tried it
> wrong.

You cannot do this inside the function.
But the __doc__ attribute is writable, so in
your module you can do something like this

sharedoc = """ (imported from module %s)""" % __name__

def somefunc():
    """I am the useless function somefunc"""
    pass

somefunc.__doc__ = somefunc.__doc__ + sharedoc

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaunstr. 26                  :    *Starship* http://starship.python.net
14163 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     where do you want to jump today?   http://www.stackless.com




More information about the Python-list mailing list