python - literalinclude : how to include only a variable using pyobject? -
i'm using sphinx document parts of python code.
i include variable class in documentation.
for example, tried without success :
.. literalinclude:: myclass.py :pyobject: myclass.avariable :language: python
i see 1 solution if code change in next release line numbers of variable change :
.. literalinclude:: myclass.py :language: python :lines: 2-3
is there solution filter variable ?
as workaround, use start-after , end-before options have add 2 comments in code before , after variables.
for example :
the class :
class myclass(): # start variables avariable = {"a":123 , "b":456} # end variables def __init__(self): pass
the rst file :
.. literalinclude:: myclass.py :start-after: # start variables :end-before: # end variables :language: python
it's not perfect, works.
Comments
Post a Comment