擅长:python、mysql、java
<p>使用Sphinx指令最简单的方法是使用注释或排除成员</p>
<p>除非严格要求在模块导入时停止变量自初始化,否则更改Python源代码是不正确的,因为您希望以这种方式显示它。如果您的Python源代码是正确的,则调整<code>.rst</code>文件以自定义表示</p>
<p>您的_module.py</p>
<pre class="lang-py prettyprint-override"><code>from pathlib import Path
class YourClass:
#: This comment is documented with the member.
path = Path('your_path', 'configfile.ini')
</code></pre>
<p>您的_module.rst(显示了两种可能的方式)</p>
<pre><code>your_module
===========
.. automodule:: your_module
:exclude-members: YourClass
.. autoclass:: YourClass
:exclude-members: path
In this example you use an annotation while excluding from autoclass.
.. autoattribute:: path
:annotation: ='write your path here'
.. autoclass:: YourClass
:noindex:
:exclude-members: path
In this example you simply exclude from autoclass.
</code></pre>
<p>结果是:</p>
<p><a href="https://i.stack.imgur.com/NJzXH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NJzXH.jpg" alt="enter image description here"/></a></p>