jupyter / jupyter/nbformat

v3.reads_py() never reads last cell

Open
#121 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
313
Forks
176
PR merge metrics
No merged PRs in 30d

Description

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

```python
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

```python
#
# Title of the notebook

#
import numpy as np
import matplotlib.pyplot as plt

#
plt.plot()

#
#
# This is some markdown documentation text, bla
#
# - with a
# - list
#
#
#
# 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 `` at the end to convert everything preceding it.

Contributor guide

Open the contributing guide

Research direction

Start at the v3.reads_py() entry point and reproduce the issue with the test.py content shown in the report. The conversion should include the final marked cell in test.ipynb without requiring a dummy cell; run the example after making the change to verify the output.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter, python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.