[英]How do I show variable names and descriptions in my Sphinx documentation?
I am using Sphinx to document my Python project. 我正在使用Sphinx记录我的Python项目。 This shows me all the methods of the project, but not any variable.
这向我显示了项目的所有方法,但没有任何变量。 I want to be able to list all variables too.
我也希望能够列出所有变量。
My code.rst is - 我的code.rst是-
Code Documentation
=====================
.. automodule:: sql_fn
:members:
Currently, my python project goes like this- 目前,我的python项目是这样的-
#test variable
var=0
test_fn():
'''test function'''
print "hello world"
How do I change code.rst or my project to show my var
and it's description test variable
also? 如何更改code.rst或项目以显示
var
及其描述test variable
?
Answering my own question- 回答我自己的问题-
To document a variable, the comment preceding it must start with a #:
instead of just a #
. 要记录变量,其前面的注释必须以
#:
开头,而不仅仅是#
。 Sphinx then recognizes it as a comment for the upcoming variable. 然后,Sphinx将其识别为即将到来的变量的注释。
#:test variable
var=0
test_fn():
'''test function'''
print "hello world"
One common approach is to document the variables in the docstring of your function. 一种常见的方法是在函数的文档字符串中记录变量。 See Google Style Python Docstrings .
请参阅Google样式Python文档字符串 。 If the variable is not in a function you should probably document it in the containing module's docstring.
如果变量不在函数中,则可能应该在包含模块的文档字符串中记录它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.