<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>That's cool!  Looks like you are creating a completely new notebook in that case.</div><div><br></div><div>I'm following this question with interest since it seems closely related to what I was trying to do in "unrolling a loop" over a sequence of cells, so I can do (almost) the same thing a bunch of times in an interactive notebook and still go back and poke around.</div>

<div><br></div><div>The suggestion there (below) was to use javascript API to execute cells.  Is there also a way to insert/modify cells into the current notebook via the javascript API?  (Is the API documented somewhere, I haven't been able to find, although some good hints here <a href="http://www.peterbouda.eu/ipython-and-javascript-interaction.html">http://www.peterbouda.eu/ipython-and-javascript-interaction.html</a> ?)</div>

<div><br></div><div>That would probably solve both of our problems?</div><div><br></div><div>Cheers,</div><div>Patrick</div><div><br></div><div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">From: Kiko <</span><a href="mailto:kikocorreoso@gmail.com" style="font-family:arial,sans-serif;font-size:12.727272033691406px">kikocorreoso@gmail.com</a><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">></span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">Subject: Re: [IPython-dev] Loop over a set of notebook cells?</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">To: IPython developers list <</span><a href="mailto:ipython-dev@scipy.org" style="font-family:arial,sans-serif;font-size:12.727272033691406px">ipython-dev@scipy.org</a><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">></span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">Message-ID:</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">        <CAB-</span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">sx600nqdnVYC3uG1Cw5S5egHQp+24_</span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">6CvgZd-TK4MXW6=</span><a href="mailto:nQ@mail.gmail.com" style="font-family:arial,sans-serif;font-size:12.727272033691406px">nQ@mail.gmail.com</a><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">></span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">Content-Type: text/plain; charset="iso-8859-1"</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">2014-03-17 19:44 GMT+01:00 MinRK <</span><a href="mailto:benjaminrk@gmail.com" style="font-family:arial,sans-serif;font-size:12.727272033691406px">benjaminrk@gmail.com</a><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">>:</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">> You can execute a cell range with a little javascript (e.g. in a</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">> %%javascript cell):</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">></span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">> var start = 2;</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">> var stop = 4;</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">></span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">> for (var i = start; i < stop; i++) {</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">>     var cell = IPython.notebook.get_cell(i);</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">>     cell.execute();</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">> }</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">></span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">></span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">Maybe this:</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">    %%javascript</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">    IPython.notebook.execute_cell_</span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">range(x,y)</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px"> with x,y the range of the cells.</span><br></div><div><br></div><div><br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
From: Fernando Perez <<a href="mailto:fperez.net@gmail.com">fperez.net@gmail.com</a>><br>
Subject: Re: [IPython-dev] generating input cells dynamically<br>
To: IPython developers list <<a href="mailto:ipython-dev@scipy.org">ipython-dev@scipy.org</a>><br>
Message-ID:<br>
        <CAHAreOo4MMSSmjJVt8D-5GH_OZT=<a href="mailto:w9fB8OK5SHvUdYWO0SZB7A@mail.gmail.com">w9fB8OK5SHvUdYWO0SZB7A@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Here:<br>
<br>
<a href="http://nbviewer.ipython.org/gist/fperez/9716279" target="_blank">http://nbviewer.ipython.org/gist/fperez/9716279</a><br>
<br>
Cheers,<br>
<br>
f<br>
<br>
<br>
On Sat, Mar 22, 2014 at 1:11 AM, Zolt?n V?r?s <<a href="mailto:zvoros@gmail.com">zvoros@gmail.com</a>> wrote:<br>
<br>
>  But LaTeX has nothing to do with the problem. The question was, given an<br>
> empty notebook, how does one *generate* the following:<br>
><br>
> In [1]: plot(sin(1*x))<br>
><br>
> In [2]: plot(sin(2*x))<br>
><br>
> In [3]: plot(sin(3*x))<br>
> .<br>
> .<br>
> .<br>
><br>
> In [200]: plot(sin(200*x))<br>
><br>
> The 200 plots have to be in separate cells, so that their order can be<br>
> changed afterwards, e.g. I want to have an IPython notebook as we<br>
> understand it, but I would like to generate its content (executable code)<br>
> dynamically. Metaprogramming, if you wish.<br>
><br>
> Zolt?n<br>
><br>
><br>
>  On 22/03/14 00:28, Paul Hobson wrote:<br>
><br>
> At this point, I have to wonder if it makes more sense to just write a<br>
> small utility to build a LaTeX document for yourself.<br>
> -paul<br>
><br>
><br>
> On Fri, Mar 21, 2014 at 12:30 PM, Zolt?n V?r?s <<a href="mailto:zvoros@gmail.com">zvoros@gmail.com</a>> wrote:<br>
><br>
>>  Hi Araron,<br>
>><br>
>> Thanks for the suggestion! But the main problem was not how to run the<br>
>> notebook, but how to generate the code in the first place. Basically, I<br>
>> would like to have a notebook that writes itself. Once it's written, it can<br>
>> be run in many ways, as you pointed out.<br>
>><br>
>> Cheers,<br>
>> Zolt?n<br>
>><br>
>>   On 21/03/14 20:13, Aaron O'Leary wrote:<br>
>><br>
>>  Once you've generated the notebook, you could use runipy to run it without<br>
>> having to go through the noteboko UI: <a href="https://github.com/paulgb/runipy/" target="_blank">https://github.com/paulgb/runipy/</a><br>
>><br>
>>  Or, if you're using IPython 2.0 you can do<br>
>><br>
>>     ipython -c "%run your_notebook.ipynb"<br>
>><br>
>> from the command line. This is the same as opening it and clicking "run<br>
>> all cells".<br>
>><br>
>> aaron<br><br>
</blockquote></div><br></div></div>