Reputation: 35331
Essentially I want to do the reverse of
ipython nbconvert --to python foo.ipynb
IOW, I want to programmatically "synthesize" iPython notebooks from Python source code1 (possibly suitably commented).
Are there any tools to do this?
FWIW, I'm a veteran Emacs user, and a recent "convert" to its org-mode
, so I particularly welcome solutions that work well with them.
1 Why I want to do this? That's a very long and tedious story, but in brief: I have to turn in homeworks for a class as *.ipynb files, but I don't like working with iPython notebooks, since I'm a mouse-phobic, text-only Emacs-head. The tools for working with iPython notebooks in Emacs are IMHO awful, if they work at all (this is actually the "long and tedious" part of the story). The only remaining course of action for me is the one this post is about.
Upvotes: 1
Views: 817
Reputation: 27853
Dragging a py file onto the dashboard should do the trick (on 2.x version), there are some special comment markers that will split the notebook on the right place. It should be programmatically doable by importing IPython.nbformat
that get all the python api to create notebooks. Some code is probably somewhere in IPython/html/
if you want to go this route and have an example, feel free to ask on IPython-dev ml, we'll be happy to help you. This part of the code is not well user-tested.
You should have a look a ipymd (ipynb+md). Cyrille is writing a book with it, and was dealing with more or less the same issue as "need to manipulate pure text".
I will also underline EIN , but the de-facto maintained fork will be the one of millejoh which is regularly updated. You will be able to directly edit ipynb file from emacs, + inline graph etc... But I guess this is one of the "tools for working with iPython notebooks in Emacs" you don't like, but future reader might be interested.
Finally I just want to point out that if the assignment are as IPython notebook (type "fill in the blanks") and are made to be graded with something like github:jupyter/nbgrader then going through pure-text might not work as ipynb might have extra metadata that wont survive the conversion.
Upvotes: 2