[IPython-User] How to create notebook (.ipynb) from iPython console (no browser)?
Sat Oct 12 10:57:40 CDT 2013
Le 12 oct. 2013 à 12:43, firstname.lastname@example.org a écrit :
> I discovered iPython and iPython notebook yesterday evening, and I find it
> great for my needs (I am a teacher in computer science); I would like to use it
> for writing some python computing exercises.
Great to hear that.
> But I work with no graphical server, and I would like to create my .ipynb
> notebooks from the console and not from a graphical browser.
> Would it be easy to implement some macros or whatever for the very simple
> following purposes:
> * use IPython from the interactive console
> * create a notebook .ipynb file for recording
> * have some macros like :
> --> add 3-15 (eg.) to the a .ipynb file according to the rule:
> as long as not output cell occurs, use the same cell;
> each time that an output occur, start a new cell (after the output)
Here you problem will be that al,oct every line produce an output value.
Sometime it might be none. But basically every time you send a bunch of code to the kernel
the AST is sliced, and the value of the last expression is returned and becomes the "output".
> --> add a H1 header with text "Hellow world" in a new cell
> --> add a H2 header with text "Hellow world" in a new cell
> --> add raw text being "Hellow world" in a new cell
> * save / exit
> Later I can review the notebook from within Firefox and make some minor fixes,
> but I would like rather having such features from IPython.
> Do you see something close to the previous ideas? Is it easy to do it?
Still what you ask shouldn't be too hard to do; .ipynb files are simple json files that are really easy to process and create by hand.
You can have a look at Ipython/nbformat/v3/* to get some utilities functions.
I suggest you have a look at defining you own magics, for example here :
And you probably want to have a look at our %history magic that will show you how to get access to
the Nth input of current session. You probably want to dig a little deeper than pure function magics
as you might want to be statefull in your work, and go toward class magics. then you could do something like:
In %open foo.ipynb
In some code
In some code
In some code
In %code 2,4
In %h2 This is a a test
Depending on what editor you use; you might want to have a look at EIN
That allow to actually talk to the notebook server and manipulate notebooks files directly
from within emacs. It might be better suited to your need.
If you have any more question, feel free to ask.
I would also suggest you to subscribe/post to ipython-dev also:
Have a look here for the why :
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-User