Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9207
| References | <e44a7596-d01f-484b-9802-1e97fbbcf30f@glegroupsg2000goo.googlegroups.com> <1310339164-sup-5162@dalek> |
|---|---|
| Date | 2011-07-10 17:16 -0700 |
| Subject | Re: Function docstring as a local variable |
| From | Chris Rebert <clp2@rebertia.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.867.1310343387.1164.python-list@python.org> (permalink) |
On Sun, Jul 10, 2011 at 4:06 PM, Corey Richardson <kb1pkl@aim.com> wrote:
> Excerpts from Carl Banks's message of Sun Jul 10 18:59:02 -0400 2011:
>> print __doc__
>>
>
> Python 2.7.1 (r271:86832, Jul 8 2011, 22:48:46)
> [GCC 4.4.5] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> def foo():
> ... "Docstring"
> ... print __doc__
> ...
>>>> foo()
> None
>>>>
>
>
> What does yours do?
The question Carl's code was in answer to was, slightly paraphrased:
"Is it possible to get a *module*'s docstring from within the module
itself?"
The question had nothing to do with *function* docstrings.
The interactive interpreter environment also isn't quite a true
module, so you can't give it a docstring or really test the relevant
feature there. Try this instead:
$ cat test.py
"""I am the docstring of the `test` module!"""
print("This module's docstring is:", __doc__)
$ python test.py
This module's docstring is: I am the docstring of the `test` module!
$
Cheers,
Chris
--
http://rebertia.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Function docstring as a local variable Carl Banks <pavlovevidence@gmail.com> - 2011-07-10 15:59 -0700
Re: Function docstring as a local variable Corey Richardson <kb1pkl@aim.com> - 2011-07-10 19:06 -0400
Re: Function docstring as a local variable alex23 <wuwei23@gmail.com> - 2011-07-10 21:14 -0700
Re: Function docstring as a local variable Andrew Berg <bahamutzero8825@gmail.com> - 2011-07-10 18:27 -0500
Re: Function docstring as a local variable Tim Johnson <tim@johnsons-web.com> - 2011-07-10 16:00 -0800
Re: Function docstring as a local variable Chris Rebert <clp2@rebertia.com> - 2011-07-10 17:09 -0700
Re: Function docstring as a local variable Chris Rebert <clp2@rebertia.com> - 2011-07-10 17:16 -0700
Re: Function docstring as a local variable Tim Johnson <tim@johnsons-web.com> - 2011-07-10 16:21 -0800
Re: Function docstring as a local variable Corey Richardson <kb1pkl@aim.com> - 2011-07-10 20:26 -0400
csiph-web