sphinx:在python中记录数据而不显示d

2024-04-26 23:43:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道我可以document (module) constants in sphinx与任何一个

#: a tuple of primes
primes = (2, 3, 5, 7, 11, 13, 17)

或者

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

然后会出现在斯芬克斯生成的文档中;即,它看起来像这样:

somemodule.primes

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

a tuple of primes

但是如果数据是一个很长的列表呢?然后我希望能够在文档中有一个docstring,但在文档中没有实际的数据本身。你知道吗

这是我想要的文件:

somemodule.primes

a tuple of primes

我有办法做到这一点吗?你知道吗


完整性:

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

autodoc: automatically insert docstrings from modules (y/n) [n]: y

我唯一添加到index.rst的是:

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

.. automodule:: somemodule
    :members:

其中somemodule.py包含:

#: a tuple of primes
primes = (2, 3, 5, 7, 11, 13, 17)

然后我在conf.py中调整sys.path,这样somemodule.py就在那条路径上。你知道吗


Tags: of数据in文档py列表sphinxdocument
1条回答
网友
1楼 · 发布于 2024-04-26 23:43:36

我结束了在somemodule.py中没有任何somemodule.primes的文档(这使得sphinx忽略了它),并在index.rst中放置了一个手动文档

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

.. automodule:: somemodule
    :members:

.. py:data:: somemodule.primes

    a tuple of primes

到目前为止,我还没有找到直接在somemodule.py中做类似事情的方法。你知道吗

相关问题 更多 >