On Tue, Aug 7, 2012 at 1:55 PM, Thomas Kluyver <takowl@gmail.com> wrote:
> On 7 August 2012 21:35, Aaron Meurer <asmeurer@gmail.com> wrote:
> > Is monkey-patching run_cell going to be as evil as it sounds?
>> It's going to be more evil than it sounds. run_cell is pretty much the
> core function of IPython, and we really don't want people
> monkeypatching it.
>
The following in one of my startup files:
shell = get_ipython()
old_run_cell = shell.run_cell
def transform(cell):
return u'\n'.join([cell, 'print "hello!"'])
def new_run_cell(cell, *args, **kwargs):
new_cell = transform(cell)
return old_run_cell(new_cell, *args, **kwargs)
shell.run_cell = new_run_cell
Lets me trivially do transforms to complete cells, without actually
changing anything *inside* run_cell. This doesn't seem too bad to me, at
least as a temporary measure while IPython gets itself an official API for
cell-level transforms.
If Prefilter/InputSplitter were not already on Thomas' chopping block, then
I would actually propose that we add a simple hook that's a list of
callables to run on the cell at the top of run_cell. But since Thomas
already plans to clean up the relevant APIs, it makes more sense to include
this as one of the use cases to consider while writing the new code.
-MinRK
>> I think for now your best bet is to use the existing prefilter API,
> and accept that it doesn't work for multiline cells yet.
>> Issue 1491 is about this. I've just bumped the priority to high,
> milestoned it for the next release and assigned myself. I'll do my
> utmost to look into this in the next few days.
>>https://github.com/ipython/ipython/issues/1491>> Thanks,
> Thomas
> _______________________________________________
> IPython-User mailing list
>IPython-User@scipy.org>http://mail.scipy.org/mailman/listinfo/ipython-user>-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20120807/b6272541/attachment.html