You cannot do this, since only a string literal is recognized as a docstring. But you can use the decorator to set or change the docstring function. (You can also explicitly change __doc__the executable code, but the decorator is much cleaner because it is logically part of the declaration).
, , , , () docstring. , ( ) docstring.
def docstring(docstr, sep="\n"):
"""
Decorator: Append to a function docstring.
"""
def _decorator(func):
if func.__doc__ == None:
func.__doc__ = docstr
else:
func.__doc__ = sep.join([func.__doc__, docstr])
return func
return _decorator
:
@docstring("copyright by nobody")
def testme():
"This function does nothing"
pass
, (, ):
from re import sub
docstring("Copyright unknown")(sub)