使用sphinx自动记录python类,模块

Ada*_*tan 21 python documentation-generation python-sphinx

我已经安装了Sphinx,以便记录一些我正在研究的python模块和类.虽然标记语言看起来非常好,但我还是没有设法自动记录python代码.

基本上,我有以下python模块:

SegLib.py
Run Code Online (Sandbox Code Playgroud)

还有一个叫它的班级Seg.我想在生成的sphinx文档中显示类和模块的文档字符串,并为其添加更多格式化文本.

index.rst看起来像这样:

Contents:

.. toctree::
:maxdepth: 2

chapter1.rst
Run Code Online (Sandbox Code Playgroud)

并且chapter1.rst:

This is a header
================
Some text, *italic text*, **bold text**

* bulleted list.  There needs to be a space right after the "*"
* item 2

.. note::
   This is a note.

See :class:`Seg`
Run Code Online (Sandbox Code Playgroud)

但是Seg只是以粗体打印,而不是与类的自动生成的文档相关联.

尝试:参见:class:Seg Module:mod:'SegLib'模块:mod:'SegLib.py'

也没有帮助.任何想法或良好的教程链接?

编辑:将SegLib更改为段(感谢,iElectric!),并将chapter1.rst更改为 ::mod:segmentsModule ------------------------- -

.. automodule:: segments.segments

.. autoclass:: segments.segments.Seg
Run Code Online (Sandbox Code Playgroud)

但是,无法让sphinx直接记录类中的函数,或者更好 - 将类中的所有函数自动添加到文档中.试着

.. autofunction:: segments.segments.Seg.sid
Run Code Online (Sandbox Code Playgroud)

得到了:

autodoc can't import/find function 'segments.segments.Seg.sid', it reported error: "No module named Seg"
Run Code Online (Sandbox Code Playgroud)

有关如何使用简短命令自动记录函数和类的任何想法?

乌迪

iEl*_*ric 14

添加到文件的开头:

.. module:: SegLib
Run Code Online (Sandbox Code Playgroud)

尝试使用:autoclass:类doc的指令.

BTW:模块名称应为lower_case.

编辑: 我从阅读其他源文件中学到了很多东西.