简体   繁体   中英

How to document Python function parameters with sphinx-apidoc?

I'm trying to clean up my python code documentation, and decided to use sphinx-doc because it looks good. I like how I can reference other classes and methods with tags like:

:class:`mymodule.MyClass` About my class.
:meth:`mymodule.MyClass.myfunction` And my cool function

I'm trying to figure out though how to document parameter names in a function, so that if I have a function like:

def do_this(parameter1, parameter2):
   """
   I can describe do_this.

   :something?:`parameter1` And then describe the parameter.

   """

What's the best practice for this?

Update:

The correct syntax is:

def do_this(parameter1, parameter2):
   """
   I can describe do_this.

   :something parameter1: And then describe the variable
   """

Typically "function variables" are called parameters ;).

It's documented here: http://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#signatures

And the answer is :param ________

EDIT Disclaimer: I've never used or heard of sphinx... This post is mostly a "what words to search for." Hope it helped.

Adding this answer to consolidate options:

pydoc is basic with no special formatting

epydoc uses the format '@param var:'

Doxygen is oriented for a larger range of languages

Sphinx uses the format ':param type var:'. Also see more examples . This was used to create the Python 3.5 documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM