![](/img/trans.png)
[英]Moving from epydoc to sphinx to auto-document a simple python .py file
[英]Using sphinx to auto-document a python class, module
我安裝了Sphinx以記錄我正在處理的一些 Python 模塊和類。 雖然標記語言看起來非常好,但我還沒有設法自動記錄 Python 代碼。
基本上,我有以下 Python 模塊:
SegLib.py
還有一個叫做Seg
的類。 我想在生成的 Sphinx 文檔中顯示類和模塊的文檔字符串,並向其中添加進一步格式化的文本。
我的index.rst
看起來像這樣:
Contents:
.. toctree::
:maxdepth: 2
chapter1.rst
和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`
但是Seg
只是以粗體打印,並沒有鏈接到該類的自動生成文檔。
嘗試以下方法也無濟於事:
See :class:`Seg`
Module :mod:'SegLib'
Module :mod:'SegLib.py'
編輯:將 SegLib 更改為段(感謝 iElectric)。 並將 chapter1:rst 更改為:
The :mod:`segments` Module
--------------------------
.. automodule:: segments.segments
.. autoclass:: segments.segments.Seg
盡管如此,仍然無法讓 Sphinx 直接記錄類中的函數,或者更好的是 - 自動將類中的所有函數添加到文檔中。 試過:
.. autofunction:: segments.segments.Seg.sid
並得到:
autodoc can't import/find function 'segments.segments.Seg.sid', it reported error: "No module named Seg"
關於如何使用簡短命令自動記錄函數和類的任何想法?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.