[IPython-dev] sample code using ipython api to get a notebook and edit it

Thomas Kluyver takowl at gmail.com
Mon Nov 17 15:10:10 EST 2014


On 17 November 2014 06:26, Robert Alexander <roalexan at microsoft.com> wrote:

> with open('test.ipynb', 'r+') as f2:


You're opening one file, reading from it, and then writing back to the same
file descriptor. That writes the new content after the end of the old
content, resulting in an invalid notebook.

To modify files, we would normally open, read, close, make the changes we
want, open, write, close.

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141117/655bcf71/attachment.html>


More information about the IPython-dev mailing list