[IPython-dev] sample code using ipython api to get a notebook and edit it
Thomas Kluyver
takowl at gmail.com
Fri Nov 14 13:42:59 EST 2014
Hi Robert,
On 14 November 2014 10:37, Robert Alexander <roalexan at microsoft.com> wrote:
> Does somebody have some sample usage of the IPython API to get and edit a
> notebook, like adding/deleting cells to/from it? So far, I've been trying
> to use the documentation at:
> http://ipython.org/ipython-doc/2/api/generated/IPython.nbformat.v3.nbbase.html,
> but I'm having a hard time getting it to work.
>
You can load a notebook with the read function. Then its cells are
accessible as a list, either at nb.worksheets[0].cells (nbformat 3), or at
nb.cells (nbformat 4 in master). You can modify it just like any Python
list. Then save it back to disk with write().
There are some changes to this API in master. We're deprecating
nbformat.current: now you will use read and write from the top level of
nbformat, and new_notebook, new_cell etc. from the version specific
subpackages, like IPython.nbformat.v4.
Best wishes,
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141114/6f8b6877/attachment.html>
More information about the IPython-dev
mailing list