sphinx:用python记录数据而不显示数据

hir*_*ist 4 python python-3.x python-sphinx

我知道我可以在 sphinx 中记录(模块)常量

#: a tuple of primes
primes = (2, 3, 5, 7, 11, 13, 17)
Run Code Online (Sandbox Code Playgroud)

或者

primes =  (2, 3, 5, 7, 11, 13, 17)
"""a tuple of primes"""
Run Code Online (Sandbox Code Playgroud)

然后它将出现在 sphinx 生成的文档中;即它看起来像这样:

somemodule.primes

= (2, 3, 5, 7, 11, 13, 17)

素数元组

但如果数据是一个很长的列表怎么办?那么我希望能够在文档中包含文档字符串,但在文档中不包含实际数据本身。

这就是我想要在文档中包含的内容:

somemodule.primes

素数元组

有什么方法可以实现这个目标吗?


为了完整性:

我运行sphinx-quickstart并启用了 autodoc:

autodoc: automatically insert docstrings from modules (y/n) [n]: y
Run Code Online (Sandbox Code Playgroud)

我唯一添加的index.rst是:

``somemodule``
**************

.. automodule:: somemodule
    :members:
Run Code Online (Sandbox Code Playgroud)

somemodule.py包含这个:

#: a tuple of primes
primes = (2, 3, 5, 7, 11, 13, 17)
Run Code Online (Sandbox Code Playgroud)

然后我就适应sys.pathconf.pysomemodule.py条道路。

Jua*_*nPi 5

以防万一有人来到这里。要隐藏变量的内容,请使用元信息列表字段

Example:

primes = (2, 3, 5, 7, 11, 13, 17)
"""A tuple of primes.

   :meta hide-value:
"""
Run Code Online (Sandbox Code Playgroud)

  • 在我手中,只有当我在指令之前省略空格时,这才有效 - 如上所示, `:meta hide-value:` 不起作用,但如果我删除了换行符和 `:meta` 之间的前导空格,那么它工作得很好。这里使用sphinx 3.5.4。 (2认同)
  • 这也可以从变量之前的“#:”注释中获取。 (2认同)