我正在使用Sphinx来记录我的部分Python代码。
我想在我的文档中只包含我的类中的一个变量。
例如,我尝试这样做,但没有成功:
.. literalinclude:: MyClass.py
:pyobject: MyClass.aVariable
:language: python我只看到一种解决方案,但如果我的代码在下一版本中发生变化,变量的行号可能会发生变化:
.. literalinclude:: MyClass.py
:language: python
:lines: 2-3有没有其他解决方案来只过滤这个变量?
发布于 2015-07-24 22:02:08
作为变通方法,我使用start-after和end- but选项,但我必须在代码中在变量之前和之后添加两个注释。
例如:
类:
class MyClass():
# Start variables
aVariable = {"a":123 , "b":456}
# End variables
def __init__(self):
passRST文件:
.. literalinclude:: MyClass.py
:start-after: # Start variables
:end-before: # End variables
:language: python它不是完美的,但它是有效的。
https://stackoverflow.com/questions/31561895
复制相似问题