gpt4 book ai didi

python - 模块内的 Sphinx autodoc 函数

转载 作者:太空狗 更新时间:2023-10-30 00:56:19 24 4
gpt4 key购买 nike

我刚刚开始使用 sphinx 并愿意学习。

我想将我的各种功能分解到我的 index.rst 文件中的不同部分。所以每个函数都有自己的标题。

例如,如果我有一个名为 test.py 的 python 文件,并且在该文件中我有 2 个函数:

def foo():
"""This prints bar"""
print("bar")

def bar():
"""This prints foo"""
print("foo")

我如何在 index.rst 中分隔我的 test.py 文件中的 2 个函数?

:mod:`test` -- foo
.. automodule:: test.foo
:members:
:undoc-members:
:show-inheritance:
:mod:`test` -- bar
.. automodule:: test.bar
:members:
:undoc-members:
:show-inheritance:

如果我能弄清楚如何分离函数,使其在 index.html 中看起来更清晰,那就太好了!如果我只运行下面的命令,现在输出不是很干净:

:mod:`test` -- these are my functions
--------------------------------------------
.. automodule:: test
:members:
:undoc-members:
:show-inheritance:

最佳答案

您可以使用 autofunction .像这样:

The test module
===============

The test module contains...

.. currentmodule:: test

The foo function
----------------

.. autofunction:: foo

The bar function
----------------

.. autofunction:: bar

关于python - 模块内的 Sphinx autodoc 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19277385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com