docstring

print(__doc__) in Python 3 script

print(__doc__) in Python 3 script Question: I can’t figure out what does the print(__doc__) do at the beginning of a script, like in this Scikit example. I have been looking for Python docstrings in google, and it seems __doc__ is useful to provide some documentation in, say, functions. But I can’t see what does __doc__ …

Total answers: 2

Multi-line description of a parameter description in python docstring

Multi-line description of a parameter description in python docstring Question: So, reStructuredText is the recommended way for Python code documentation, if you try hard enough, you can find in the sphinx documentation how to normalize your function signature documentation. All given examples are single-line, but what if a parameter description is multi-line like the following …

Total answers: 5

Python docstrings and inline code; meaning of the ">>>" syntax

Python docstrings and inline code; meaning of the ">>>" syntax Question: I have some experience in Python but only recently came across extensive usage of docstrings. I’m going through the Financial Market Simulator (FMS) source code, and when I open it in PyCharm I see the following syntax highlighting (screenshot of a code snippet of …

Total answers: 3

Docstrings when nothing is returned

Docstrings when nothing is returned Question: What is the docstring convention when a function doesn’t return anything? For example: def f(x): “””Prints the element given as input Args: x: any element Returns: “”” print “your input is %s” % x return What should I add after Returns: in the docstring? Nothing as it is now? …

Total answers: 2

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

Custom PyCharm docstring stubs (i.e. for google docstring or numpydoc formats) Question: Does PyCharm 2.7 (or will PyCharm 3) have support for custom docstring and doctest stubs? If so, how does one go about writing this specific type of custom extension? My current project has standardized on using the Google Python Style Guide (http://google-styleguide.googlecode.com/svn/trunk/pyguide.html). I …

Total answers: 3

Documenting `tuple` return type in a function docstring for PyCharm type hinting

Documenting `tuple` return type in a function docstring for PyCharm type hinting Question: How can I document that a function returns a tuple in such a way that PyCharm will be able to use it for type hinting? Contrived example: def fetch_abbrev_customer_info(customer_id): “””Pulls abbreviated customer data from the database for the Customer with the specified …

Total answers: 1

How to specify that a parameter is a list of specific objects in Python docstrings

How to specify that a parameter is a list of specific objects in Python docstrings Question: I really like using docstrings in Python to specify type parameters when projects get beyond a certain size. I’m having trouble finding a standard to use to specify that a parameter is a list of specific objects, e.g. in …

Total answers: 4

Triple-double quote v.s. Double quote

Triple-double quote v.s. Double quote Question: What is the preferred way to write Python doc string? """ or " In the book Dive Into Python, the author provides the following example: def buildConnectionString(params): """Build a connection string from a dictionary of parameters. Returns string.""" In another chapter, the author provides another example: def stripnulls(data): "strip …

Total answers: 4

PEP 257 docstring trim in standard library?

PEP 257 docstring trim in standard library? Question: PEP 257 says: Docstring processing tools will strip a uniform amount of indentation from the second and further lines of the docstring, equal to the minimum indentation of all non-blank lines after the first line. Any indentation in the first line of the docstring (i.e., up to …

Total answers: 1