简体   繁体   English

如何在Sphinx文档中显示变量名称和描述?

[英]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.

相关问题 如何在 Sphinx 文档的每一页上添加目录? - How do I add a Table of Contents to every page in my Sphinx Documentation? 如何在Linux中安装python的sphinx文档生成器? - How do I install python's sphinx documentation generator in linux? 我可以在 Sphinx 文档中抑制变量扩展吗? - Can I suppress variable expansion in Sphinx documentation? 在Sphinx中嵌入matplotlib图:如何显示文档 - Embedding matplotlib plots in Sphinx: how to show documentation 如何从我的 .rst 文件访问 sphinx conf.py 中的变量? - How do I access a variable in sphinx conf.py from my .rst file? 在 Sphinx 文档中显示 *only* 文档字符串? - Show *only* docstring in Sphinx documentation? 如何使用Sphinx为1文件python项目(脚本,无模块)生成文档? - How do i generate a documentation for a 1-file python project (script, no module) with sphinx? 如何为 Google App Engine 项目构建 sphinx (readthedocs) 文档? - How do I build sphinx (readthedocs) documentation for Google App Engine projects? 如何在Sphinx生成的文档中添加“上一章”和“下一章”链接? - How do I add a 'previous chapter' and 'next chapter' link in documentation generated by Sphinx? 如何在 Pycharm 中显示官方 sphinx 示例和模块文档 - How to show official sphinx examples and documentation of modules in Pycharm
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM