[IPython-dev] cell-to-function extension

Fernando Perez fperez.net at gmail.com
Wed Feb 26 21:10:23 EST 2014


Thomas, many thanks! When the history of IPython is written, we'll have to
have a chapter about Lucky House Thai ;)


On Wed, Feb 26, 2014 at 5:40 PM, Thomas Kluyver <takowl at gmail.com> wrote:

> Several people have mentioned that it's awkward when you want to reuse
> exploratory code written in a notebook, first by moving it into a function
> for other cells in the same notebook, and then by moving it into a module
> to use from other notebooks and other modules.
>
> At lunch today, we came up with the idea of a tool to transform a cell
> into a function, to address the first of those steps. Indenting and adding
> 'def foo()' by hand is easy enough, but in large cells it's easy to
> overlook a critical variable. So the tool scans the code in the cell, and
> creates function parameters for any variables referenced before they're
> defined, along with a return statement including any variables defined in
> the cell. That will usually be more than you want, but deleting code is
> easier than writing it.
>
> Using the extension is as simple as putting a "%%cell2function" at the top
> of cells you want to turn into a function. Please give the extension a try
> and let me know whether it's useful in your workflow, and any annoyances
> you find using it.
>
> Install command:
>
> %install_ext https://raw.github.com/takluyver/cell2function/master/cell2function.py
>
> Github project: https://github.com/takluyver/cell2function
> Example notebook:
> http://nbviewer.ipython.org/github/takluyver/cell2function/blob/master/Cell2function%20demo.ipynb
>
> Thanks,
> Thomas
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>


-- 
Fernando Perez (@fperez_org; http://fperez.org)
fperez.net-at-gmail: mailing lists only (I ignore this when swamped!)
fernando.perez-at-berkeley: contact me here for any direct mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140226/644dd17d/attachment.html>


More information about the IPython-dev mailing list