nbformat icon indicating copy to clipboard operation
nbformat copied to clipboard

v3.reads_py() never reads last cell

Open nils-werner opened this issue 7 years ago • 1 comments

I am using the following to convert a python script to a notebook:

from nbformat import v3, v4

with open("test.py") as fpin:
    nbook = v3.reads_py(fpin.read())

nbook = v4.upgrade(nbook)

with open("test.ipynb", "w") as fpout:
    fpout.write(v4.writes(nbook) + "\n")

However using the following test.py file

# <headingcell level=1>
# Title of the notebook

# <codecell>
import numpy as np
import matplotlib.pyplot as plt

# <codecell>
plt.plot()

# <markdowncell>
#
# This is some markdown documentation text, bla
#
#  - with a
#  - list
#
# <rawcell>
#
# The last cell is never imported, so we need with this pointless cell

I realized that the last <*cell> is never read and never ends up in test.ipynb, so I have to add a dummy <rawcell> at the end to convert everything preceding it.

nils-werner avatar Mar 07 '18 09:03 nils-werner

We're no longer supporting reading and writing notebooks in py files, and the functions to do so are not documented. Feel free to fork that code into your own project if you want to use it, though.

takluyver avatar Mar 07 '18 09:03 takluyver