I know what's the standard way to document functions, classes and modules, but how do I document packages - do I put a docstring in __init__.py
, or something else?
To tell Python that a particular directory is a package, we create a file named __init__.py inside it and then it is considered as a package and we may create other modules and sub-packages within it. This __init__.py file can be left blank or can be coded with the initialization code for the package.
You can use help() function to display the documentation. or you can choose method. __doc__ descriptor. Eg: help(input) will give the documentation on input() method.
Sphinx is far and away the most popular Python documentation tool. Use it. It converts reStructuredText markup language into a range of output formats including HTML, LaTeX (for printable PDF versions), manual pages, and plain text. There is also great, free hosting for your Sphinx docs: Read The Docs.
Yes, just like for a function or class comment, the first item in the __init__.py file should be a comment string:
"""
This is the xyz package.
"""
Now if you import the package, and use help(package), you will see your docstring. See more here: http://www.python.org/dev/peps/pep-0257/
See PEP257
A package may be documented in the module docstring of the __ init __.py file in the package directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With