Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9204

Re: Function docstring as a local variable

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: Function docstring as a local variable
References <mailman.842.1310319682.1164.python-list@python.org> <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> <mailman.855.1310336914.1164.python-list@python.org>
Date 2011-07-11 09:48 +1000
Message-ID <87d3hhg0ip.fsf@benfinney.id.au> (permalink)
Organization Unlimited download news at news.astraweb.com

Show all headers | View raw


"Colin J. Williams" <cjw@ncf.ca> writes:

> On 10-Jul-11 13:44 PM, rantingrick wrote:
> > On Jul 10, 12:41 pm, Tim Johnson<t...@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Function docstring as a local variable Tim Johnson <tim@johnsons-web.com> - 2011-07-10 09:41 -0800
  Re: Function docstring as a local variable rantingrick <rantingrick@gmail.com> - 2011-07-10 10:44 -0700
    Re: Function docstring as a local variable "Colin J. Williams" <cjw@ncf.ca> - 2011-07-10 18:28 -0400
      Re: Function docstring as a local variable Ben Finney <ben+python@benfinney.id.au> - 2011-07-11 09:48 +1000
    Re: Function docstring as a local variable Corey Richardson <kb1pkl@aim.com> - 2011-07-10 19:00 -0400
      Re: Function docstring as a local variable Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-11 11:54 +1000
      Re: Function docstring as a local variable alex23 <wuwei23@gmail.com> - 2011-07-10 21:05 -0700

csiph-web