I'm using Sphinx to document parts of my Python code.
I would like to include only a variable from my class in my documentation.
For example, I tried this but without success :
.. literalinclude:: MyClass.py
:pyobject: MyClass.aVariable
:language: python
I see only one solution but if my code change in the next release the line numbers of the variable could change :
.. literalinclude:: MyClass.py
:language: python
:lines: 2-3
Is there another solution to filter only this variable ?
As workaround, I use the start-after and end-before options but I have to add two comments in my code before and after the 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, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With