Using javadoc for Python documentation
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Dreamlands
--
Chapters
00:00 Using Javadoc For Python Documentation
01:03 Answer 1 Score 26
01:25 Accepted Answer Score 233
02:24 Answer 3 Score 1
02:47 Answer 4 Score 79
03:20 Thank you
--
Full question
https://stackoverflow.com/questions/5334...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #documentation #javadoc #docstring
#avk47
ACCEPTED ANSWER
Score 233
Have a look at the reStructuredText (also known as "reST") format, which is a plaintext/docstring markup format, and probably the most popular in the Python world. And you should certainly look at Sphinx, a tool to generate documentation from reStructuredText (used for eg. the Python documentation itself). Sphinx includes the possibility to extract documentation from the docstrings in your code (see sphinx.ext.autodoc), and recognizes reST field lists following certain conventions. This has probably become (or is becoming) the most popular way to do it.
Your example could look as follows:
"""Replace template placeholder with values.
:param timestamp: formatted date to display
:param priority: priority number
:param priority_name: priority name
:param message: message to display
:returns: formatted string
"""
Or extended with type information:
"""Replace template placeholder with values.
:param timestamp: formatted date to display
:type timestamp: str or unicode
:param priority: priority number
:type priority: str or unicode
:param priority_name: priority name
:type priority_name: str or unicode
:param message: message to display
:type message: str or unicode
:returns: formatted string
:rtype: str or unicode
"""
ANSWER 2
Score 79
Follow Google Python Style Guide. Note that Sphinx can also parse this format using the Napolean extension, which will come packaged with Sphinx 1.3 (this is also compatible with PEP257):
def func(arg1, arg2):
    """Summary line.
    Extended description of function.
    Args:
        arg1 (int): Description of arg1
        arg2 (str): Description of arg2
    Returns:
        bool: Description of return value
    """
    return True
Example taken from the Napolean documentation linked above.
A comprehensive example on all types of docstrings here.
ANSWER 3
Score 26
The standard for python documentation strings is described in Python Enhancement Proposal 257.
The appropriate comment for your method would be something like
def format(...):
    """Return timestamp string with place holders replaced with values.
    Keyword arguments:
    timestamp     -- the format string (default '')
    priority      -- priority number (default '')
    priority_name -- priority name (default '')
    message       -- message to display (default '')
    """
ANSWER 4
Score 1
Take a look at Documenting Python, a page "aimed at authors and potential authors of documentation for Python."
In short, reStructuredText is what's used for documenting Python itself. The developer's guide contains a reST primer, style guide, and general advice for writing good documentation.