<pclass="last">This tutorial should be read side-by-side with the Sphinc source
for this document (see <aclass="reference internal" href="#ipython-literal"><spanclass="std std-ref">Sphinx source for this tutorial</span></a>) because otherwise
you will see only the rendered output and not the code that
generated it. Excepting the example above, we will not in general
be showing the liuteral rest in this document that generates the
rendered output.</p>
</div>
<p>The state from previous sessions is stored, and standard error is
trapped. At doc build time, ipython’s output and std err will be
inserted, and prompts will be renumbered. So the prompt below should
be renumbered in the rendered docs, and pick up where the block above
left off.</p>
<divclass="highlight-ipython"><divclass="highlight"><pre><span></span><spanclass="gp">In [3]: </span><spanclass="n">z</span><spanclass="o">=</span><spanclass="n">x</span><spanclass="o">*</span><spanclass="mi">3</span><spanclass="c1"># x is recalled from previous block</span>
<spanclass="go"> File "<ipython-input-5-771f2b45b9f9>", line 1</span>
<spanclass="go"> print z</span>
<spanclass="go"> ^</span>
<spanclass="go">SyntaxError: Missing parentheses in call to 'print'</span>
<spanclass="gp">In [6]: </span><spanclass="n">q</span><spanclass="o">=</span><spanclass="n">z</span><spanclass="p">[)</span><spanclass="c1"># this is a syntax error -- we trap ipy exceptions</span>
<spanclass="go"> File "<ipython-input-6-9e4a6c3ff9f7>", line 1</span>
<spanclass="go"> q = z[) # this is a syntax error -- we trap ipy exceptions</span>
<spanclass="gt"> File</span><spanclass="nn"> "<ipython-input-11-f46480457c17>"</span><spanclass="gt">, line </span><spanclass="mi">1</span>
<spanclass="gt"> File</span><spanclass="nn"> "<ipython-input-14-2d264e11d975>"</span><spanclass="gt">, line </span><spanclass="mi">1</span>
<p>Likewise, you can set <codeclass="docutils literal"><spanclass="pre">:doctest:</span></code> or <codeclass="docutils literal"><spanclass="pre">:verbatim:</span></code> to apply these
<h2>Pseudo-Decorators<aclass="headerlink" href="#pseudo-decorators" title="Permalink to this headline">¶</a></h2>
<p>Here are the supported decorators, and any optional arguments they
take. Some of the decorators can be used as options to the entire
block (eg <codeclass="docutils literal"><spanclass="pre">verbatim</span></code> and <codeclass="docutils literal"><spanclass="pre">suppress</span></code>), and some only apply to the
line just below them (eg <codeclass="docutils literal"><spanclass="pre">savefig</span></code>).</p>
<p>@suppress</p>
<blockquote>
<div>execute the ipython input block, but suppress the input and output
block from the rendered output. Also, can be applied to the entire
<codeclass="docutils literal"><spanclass="pre">..ipython</span></code> block as a directive option with <codeclass="docutils literal"><spanclass="pre">:suppress:</span></code>.</div></blockquote>
<p>@verbatim</p>
<blockquote>
<div>insert the input and output block in verbatim, but auto-increment
the line numbers. Internally, the interpreter will be fed an empty
string, so it is a no-op that keeps line numbering consistent.
Also, can be applied to the entire <codeclass="docutils literal"><spanclass="pre">..ipython</span></code> block as a
directive option with <codeclass="docutils literal"><spanclass="pre">:verbatim:</span></code>.</div></blockquote>
<p>@savefig OUTFILE [IMAGE_OPTIONS]</p>
<blockquote>
<div>save the figure to the static directory and insert it into the
document, possibly binding it into a minipage and/or putting
code/figure label/references to associate the code and the
figure. Takes args to pass to the image directive (<em>scale</em>,
<em>width</em>, etc can be kwargs); see <aclass="reference external" href="http://docutils.sourceforge.net/docs/ref/rst/directives.html#image">image options</a>
for details.</div></blockquote>
<p>@doctest</p>
<blockquote>
<div>Compare the pasted in output in the ipython block with the output
generated at doc build time, and raise errors if they don’t
match. Also, can be applied to the entire <codeclass="docutils literal"><spanclass="pre">..ipython</span></code> block as a
directive option with <codeclass="docutils literal"><spanclass="pre">:doctest:</span></code>.</div></blockquote>
<spanid="ipython-literal"></span><h2>Sphinx source for this tutorial<aclass="headerlink" href="#sphinx-source-for-this-tutorial" title="Permalink to this headline">¶</a></h2>