'How to use a long string as a descriptive docstring for a number of functions
I have created a util python file that contains many functions in it. I want to use a long string to be used as a descriptive docstring for some of them, which can be shown with help(functionname)
. Is it possible to write the string just one time and use it for the desired functions (by referring that string from within the functions) as it can be shown with help
?
For example (the main docstring is a long multiline string, here is just as an example):
longstring = """ It is the description """
def hello_():
longstring
return 'hello'
def by_():
longstring
return 'by'
# help(hello_) shows the longstring
I used a code similar to above, but that doesn't show that docstring.
Solution 1:[1]
You can try function.__doc__ = "some string"
, but note this only works with functions.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Shib |