.__doc__
est le meilleur choix. Cependant, vous pouvez également utiliser inspect.getdoc
pour obtenir docstring
. Un avantage de l'utilisation de ceci est qu'il supprime l'indentation des docstrings qui sont indentées pour s'aligner avec des blocs de code.
Exemple:
In [21]: def foo():
....: """
....: This is the most useful docstring.
....: """
....: pass
....:
In [22]: from inspect import getdoc
In [23]: print(getdoc(foo))
This is the most useful docstring.
In [24]: print(getdoc(str))
str(object='') -> string
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.