[IPython-dev] Loop over a set of notebook cells?
Patrick Surry
patrick.surry at gmail.com
Sat Mar 15 07:18:12 EDT 2014
What about a "loop delimiter" magic where you insert a matching pair of
%magics bracketing a sequence of regular cells, and then it basically
unrolls the loop for you?
i.e. when you run the magic, on the first loop iteration it executes each
cell in place, with the first loop value, and for each subsequent
iterations, it appends a copied sequence of new cells after the %end,
evaluated with the corresponding loop element. So if you looped over a
list of two items, you'd end up with a second copy of all your looped cells
that have been executed with the second item in the list. (see example
sketch below)
So it's doing a kind of repeated block copy & paste (useful in it's own
right), unrolling the loop, and leaving you the new results to explore and
further tweak. Maybe it would also mark itself as executed somehow
(comment itself out?!) so the notebook is stable if you re-execute all
cells?
You'd rapidly want multi-cell delete I guess :) Perhaps other bracketing
magics like %block cut / %endblock / %block paste ??
Patrick
Example with cells a, b, c:
%begin for item in [1,2]
---
a
---
b
---
c
---
%end
when executed becomes:
# %begin for item in [1, 2]
---
a [item=1]
---
b [item=1]
---
c [item=1]
---
# %end
---
a [item=2]
---
b [item=2]
---
c [item=2]
---
From: Thomas Kluyver <takowl at gmail.com>
>On 14 March 2014 09:46, Nikolas Tezak <ntezak at stanford.edu> wrote:
> I've been thinking about this for a while as well. Although this doesn't
> quite address looping, I think one idea might be to use cell tags to
create
> certain "run sets" of cells and then have a little widget/ui component
that
> allows for selecting and running all cells of a certain tag. So, in that
> respect a good interface for marking/selecting multiple cells and then
> tagging them or running them or copying them would be great.
Tags on cells is something that we want to do - there are a lot of useful
things that could be done with it.
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140315/3280849b/attachment.html>
More information about the IPython-dev
mailing list