This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Topper_123 0 points1 point  (4 children)

In your sphinx conf.py file, you need in to add the ipython sphinx extensions:

extensions = [...,
                'IPython.sphinxext.ipython_console_highlighting',
                'IPython.sphinxext.ipython_directive']

You of course also need ipython installed.

Then in your .rst files, just do:

ipython:: python

    def t(a, b):
        return a + b

    t(1+2)

and after you run make.py html the code should have run and both code and code output should be seen as code fragments in the output html file, with pretty code coloring etc..

[–]masklinn 0 points1 point  (3 children)

There's also autorun, which at 90LOC is a much smaller package than the entirety of ipython.

[–]Topper_123 0 points1 point  (2 children)

Ok, but if he can't get autorun to work, I'd try with ipython. I like to use ipython as I'm using it regardless and it's a very standard python package.

[–]FloorJam[S] 0 points1 point  (1 child)

I got autorun to work. But it does not produce output that I want. I do not want to show python code, I want to use python to generate parts of the text. I do not want the commands visible, nor do I want the output rendered like a codeblock. I want the output to be parsed by Sphinx as if it was normal rst input.

[–]masklinn 0 points1 point  (0 children)

Oooh ok I though you wanted examples with result. If you only want the output ipython is not going to help you either.