[IPython-dev] Best approach for uploading files through the Notebook?

Brian Granger ellisonbg@gmail....
Wed Jun 27 15:20:55 CDT 2012


Let's say you want to create an %upload magic for this purpose.

1. First create a magic function using this approach:

http://ipython.org/ipython-doc/dev/interactive/reference.html#defining-your-own-magics

2. Your magic function should do something like this:

from IPython.core.display import display, Javascript

display(Javascript('your JS code goes here'))

3. Then you need to write the JS code to open the file browser, read
the file and send it back to the kernel using kernel.execute.

On Wed, Jun 27, 2012 at 1:14 PM, Carl Smith <carl.input@gmail.com> wrote:
> I want to have a go at doing what Matthius proposed, but need a few
> pointers. I know I can use IPython.notebook.kernel.execute in the
> JavaScript to control the kernel. Is this the only method for the
> JavaScript to chat to the kernel?

Yep, basically.

> I also don't know how to get the kernel to channel data back to the
> JavaScript. I know Brian demonstrated that this can be done, but I
> can't find any example code that covers it. I read somewhere that it
> required some changes to the Notebook, and there was a PR for this, is
> this still true, or does the current dev version support this stuff
> out the box?

The dev version supports everything you need.

Cheers,

Brian

> Thanks Matthius for your help on this issue, and to everyone on the
> list for your patience, I do appreciate it very much.
>
> Carl
> _______________________________________________
> IPython-dev mailing list
> IPython-dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev



-- 
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com


More information about the IPython-dev mailing list