[IPython-dev] generating input cells dynamically

Patrick Surry patrick.surry at gmail.com
Sat Mar 22 20:10:10 EDT 2014


That's cool!  Looks like you are creating a completely new notebook in that
case.

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.

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
http://www.peterbouda.eu/ipython-and-javascript-interaction.html ?)

That would probably solve both of our problems?

Cheers,
Patrick

From: Kiko <kikocorreoso at gmail.com>
Subject: Re: [IPython-dev] Loop over a set of notebook cells?
To: IPython developers list <ipython-dev at scipy.org>
Message-ID:
        <CAB-sx600nqdnVYC3uG1Cw5S5egHQp+24_6CvgZd-TK4MXW6=nQ at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

2014-03-17 19:44 GMT+01:00 MinRK <benjaminrk at gmail.com>:

> You can execute a cell range with a little javascript (e.g. in a
> %%javascript cell):
>
> var start = 2;
> var stop = 4;
>
> for (var i = start; i < stop; i++) {
>     var cell = IPython.notebook.get_cell(i);
>     cell.execute();
> }
>
>
Maybe this:

    %%javascript
    IPython.notebook.execute_cell_range(x,y)

 with x,y the range of the cells.


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


More information about the IPython-dev mailing list