Skip to content

Commit

Permalink
Backport PR #10558: Let nbformat take care of opening the file
Browse files Browse the repository at this point in the history
Notebook files should always be read as utf-8, but the default for `io.open()` is to use a platform-dependent default encoding. The easiest way around this is to pass the filename to nbformat.read() and let it open the file correctly.

Bug identified at: http://stackoverflow.com/questions/43915006/encoding-error-in-jupyter-when-run-another-notebook
  • Loading branch information
Carreau authored and MeeseeksDev[bot] committed May 13, 2017
1 parent e0d9c06 commit b441be7
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -2535,13 +2535,12 @@ def get_cells():
"""generator for sequence of code blocks to run"""
if fname.endswith('.ipynb'):
from nbformat import read
with io_open(fname) as f:
nb = read(f, as_version=4)
if not nb.cells:
return
for cell in nb.cells:
if cell.cell_type == 'code':
yield cell.source
nb = read(fname, as_version=4)
if not nb.cells:
return
for cell in nb.cells:
if cell.cell_type == 'code':
yield cell.source
else:
with open(fname) as f:
yield f.read()
Expand Down

0 comments on commit b441be7

Please sign in to comment.