[Tutor] how to reference a function itself when accessing its private functions?

Kent Johnson kent37 at tds.net
Tue May 5 01:55:25 CEST 2009


On Mon, May 4, 2009 at 6:37 PM, Tim Michelsen
<timmichelsen at gmx-topmail.de> wrote:

> Who can I reference the docstring of a function within the function itself?

You can refer to the function by name inside the function. By the time
the body is actually executed, the name is defined:
In [1]: def show2(s):
   ...:     """prints s"""
   ...:     print s
   ...:     print show2.__doc__

In [2]: show2("test")
test
prints s

> Please have a look at the code below and assist me.
>
> def show(str):
>    """prints str"""
>    print str

It's a good idea not to use the names of builtins, such as 'str', as
variable names in your program.

Kent


More information about the Tutor mailing list