问题
I am just getting started with sphinx and willing to learn.
I would like to break up my various functions into different sections within my index.rst
file. So each function has it's own header.
So for example if I have a python file named test.py
and within that file I have 2 functions:
def foo():
"""This prints bar"""
print("bar")
def bar():
"""This prints foo"""
print("foo")
How could I within the index.rst
separate the 2 functions within my test.py file?
:mod:`test` -- foo
.. automodule:: test.foo
:members:
:undoc-members:
:show-inheritance:
:mod:`test` -- bar
.. automodule:: test.bar
:members:
:undoc-members:
:show-inheritance:
If I can figure out how to separate the functions so it looks cleaner in the index.html
that would be great! As it is now the output is not very clean if I just run the following below:
:mod:`test` -- these are my functions
--------------------------------------------
.. automodule:: test
:members:
:undoc-members:
:show-inheritance:
回答1:
You can use autofunction. Like this:
The test module
===============
The test module contains...
.. currentmodule:: test
The foo function
----------------
.. autofunction:: foo
The bar function
----------------
.. autofunction:: bar
来源:https://stackoverflow.com/questions/19277385/sphinx-autodoc-functions-within-module