Reputation: 12874
I want to write a book using Sphinx and restructured text. As most of the content will be solutions written in Python I want to separate the text and the code.
Is there a command to add external python scripts to my restructured text documents?
I tried to use
.. code-block:: python
.. include:: unittest_exp1.py
and
.. code-block:: python
.. file:: unittest_exp1.py
Upvotes: 4
Views: 658
Reputation: 22459
Have you try .. literalinclude:: filename?
Here is a little example:
.. literalinclude:: filename
:linenos:
:language: python
:lines: 1, 7-8
:start-after: 12
:end-before: 5
Upvotes: 3
Reputation:
Use literalinclude as shown in the Sphinx documentation.
.. literalinclude:: example.py
:language: python
:emphasize-lines: 12,15-18
:linenos:
Upvotes: 5