小编Sim*_*onF的帖子

python autodoc元组/列表格式可以更改吗?

我要记录的项目中有一些python代码,但是在记录元组或列表的类常量时遇到了问题。请参见下面的代码和图像。当每行上有多个项目并且行是随机拆分时,很难阅读文档。

元组可以用其他方式格式化吗?就像新行中的每个元素一样。我仍然想使用autodoc(在整个文件上),因此手动添加类是不可接受的。我可以更改代码,conf.py或自动模块选项。

第一个:

.. automodule:: my_python_file
    :members:
    :undoc-members:
Run Code Online (Sandbox Code Playgroud)

my_python_file.py:

class SOMinimalExample:
    """SO example with ugly formatted tuple"""
    MY_CONSTANT = (
        ('AnElement', (1, 2, 3, 5)),
        ('AnotherElement', (3, 5)),
        ('MoreElements', (1, 5)),
        ('MoreElements', (1, 5, 5)),
        ('MoreElements', (213, )),
        ('MoreElements', (5, 1, 5)),
        ('MoreElements', (1, 8, 5)),
        ('MoreElements', (1, 0, 0, 0, 5)),
        ('MoreElements', (1, 123, 4324, 46, 845)),
    )
Run Code Online (Sandbox Code Playgroud)

输出:

渲染输出

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" …
Run Code Online (Sandbox Code Playgroud)

python python-sphinx autodoc

5
推荐指数
1
解决办法
170
查看次数

标签 统计

autodoc ×1

python ×1

python-sphinx ×1