Multi-line description of a parameter description in python docstring

Good research effort from the Original Poster. It is a surprise that the canonical sphinx documentation does not give a multi-line example on params, despite the fact that multi-line document is inevitable due to the 79-character guideline in PEP8. In practice, considering that your parameter name itself is typically a word or even longer snake_case_words, … Read more

print(__doc__) in Python 3 script

it seems __doc__ is useful to provide some documentation in, say, functions This is true. In addition to functions, documentation can also be provided in modules. So, if you have a file named mymodule.py like this: “””This is the module docstring.””” def f(x): “””This is the function docstring.””” return 2 * x You can access … Read more

Is there a consensus on what should be documented in the class and __init__ docstrings?

There is an official answer, in PEP 257 (the docstring PEP), which is arguably authoritative: The class constructor should be documented in the docstring for its __init__ method. This is quite logical, as this is the usual procedure for functions and methods, and __init__() is not an exception. As a consequence, this puts the code … Read more

How to print Docstring of python function from inside the function itself?

def my_func(): “””Docstring goes here.””” print my_func.__doc__ This will work as long as you don’t change the object bound to the name my_func. new_func_name = my_func my_func = None new_func_name() # doesn’t print anything because my_func is None and None has no docstring Situations in which you’d do this are rather rare, but they do … Read more

Custom PyCharm docstring stubs (i.e. for google docstring or numpydoc formats)

With PyCharm 5.0 we finally got to select Google and NumPy Style Python Docstrings templates. It is also mentioned in the whatsnew section for PyCharm 5.0. How to change the Docstring Format: File –> Settings –> Tools –> Python Integrated Tools There you can choose from the available Docstrings formats: Plain, Epytext, reStructuredText, NumPy, Google … Read more

Adding docstrings to namedtuples?

In Python 3, no wrapper is needed, as the __doc__ attributes of types is writable. from collections import namedtuple Point = namedtuple(‘Point’, ‘x y’) Point.__doc__ = ”’\ A 2-dimensional coordinate x – the abscissa y – the ordinate”’ This closely corresponds to a standard class definition, where the docstring follows the header. class Point(): ”’A … Read more