Skip to main content
 首页 » 编程设计

python之如何省略 Sphinx 上的变量值

2024年10月25日8think

我有一些模块级变量,它们的值又长又无趣,我想将其从自动生成的文档中排除。有办法做到这一点吗?

例如,在我的 Python 源代码中,我有类似的东西

#:This is a variable with a log value. 
long_variable = "Some really long value that is not really of interest and just kind of gets in the way of reading and understanding what's going on." 

在我的 Sphinx 源代码中有

.. automodule:: the_module 
   :members: 

并且我希望文档省略变量值。

如何在 Sphinx 上省略变量值?有没有办法在特定变量的 Python 源代码中执行此操作?我可以在 Sphinx 源代码中对整个模块或单个变量执行此操作吗?

请您参考如下方法:

要隐藏变量的内容,请使用元信息列表字段 https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#info-field-lists .

可以在这里找到一个例子https://stackoverflow.com/a/67999830/487993