.__doc__
jest najlepszym wyborem. Możesz jednak użyć inspect.getdoc
, aby uzyskać docstring
. Jedną z zalet użycia tego jest to, że usuwa wcięcia z docstrukcji, które są wcięte do wyrównania z blokami kodu.
przykład:
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.