The docstring function for the function is available as a special attribute __doc__.
>>> def f(x):
... "return the square of x"
... return x * x
>>> f.__doc__
'return the square of x'
>>> help(f)
(help page with appropriate docstring)
>>> f.__doc__ = "Return the argument squared"
>>> help(f)
(help page with new docstring)
This demonstrates the technique, anyway. In practice, you can:
def f(x):
return x * x
f.__doc__ = """
Return the square of the function argument.
Arguments: x - number to square
Return value: x squared
Exceptions: none
Global variables used: none
Side effects: none
Limitations: none
"""
... or whatever you want to insert into your docstrings.
source
share