【问题标题】:Sphinx autodoc functions within module模块内的 Sphinx 自动文档功能
【发布时间】:2013-10-09 16:17:21
【问题描述】:

我刚刚开始接触 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:

【问题讨论】:

    标签: python documentation python-sphinx docstring autodoc


    【解决方案1】:

    您可以使用autofunction。像这样:

    The test module
    ===============
    
    The test module contains...
    
    .. currentmodule:: test
    
    The foo function
    ----------------
    
    .. autofunction:: foo
    
    The bar function
    ----------------
    
    .. autofunction:: bar
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多