Function docstring as a local variable
Ben Finney
ben+python at benfinney.id.au
Sun Jul 10 19:48:46 EDT 2011
"Colin J. Williams" <cjw at ncf.ca> writes:
> On 10-Jul-11 13:44 PM, rantingrick wrote:
> > On Jul 10, 12:41 pm, Tim Johnson<t... at johnsons-web.com> wrote:
> >> It possible for a function to print it's own docstring?
> >
> > def f():
> > """docstring"""
> > print "docstring"
>
> Try:
>
> def f():
> ds= """docstring"""
> print ds
The OP wants the function to print its own docstring, which your example
does not do. You've defined a function with an empty docstring.
>>> def foo():
... ds = "The Larch"
... print ds
...
>>> foo.__doc__
>>>
--
\ “Firmness in decision is often merely a form of stupidity. It |
`\ indicates an inability to think the same thing out twice.” |
_o__) —Henry L. Mencken |
Ben Finney
More information about the Python-list
mailing list