2

I use cyrillic symbols in my Jupyter notebooks.
In NoteBook №1 I run NoteBook №2.

%run ./NB2.ipynb

In NoteBook №2 I write in some txt file.

TestText = open('C:\\TRASH\\test_text.txt', 'w')
a = 'Иридий' #Iridium
TestText.write(a+'\n')
TestText.close()

And when NB1 starts I get UnicodeDecodeError.

...can't decode byte 0x98

Full output is there: http://collabedit.com/tcev6

Briefly, Nbformat library call core.reads which, in its turn, read NB2 in win-1251 encoding. That's why first 'И' is the problem.

Is there a regular way to choose the encoding for reading second notebook?

Marya
  • 64
  • 6
  • Notebooks are always saved with UTF-8 encoding - it's a bug in IPython that it's trying to read it as cp-1251. If you want to file an issue, I should be able to fix this easily tomorrow if no-one gets there first. – Thomas K May 11 '17 at 21:22
  • 1
    I've opened a PR to fix this: https://github.com/ipython/ipython/pull/10558 – Thomas K May 13 '17 at 14:32

2 Answers2

0

pls ref:

https://nbviewer.jupyter.org/gist/minrk/5491090/analysis.ipynb
change "with io.open(nbfile) as f:"
to "with io.open(nbfile,encoding="utf-8") as f:"
argo
  • 1
0

https://github.com/ipython/ipython/pull/10558 This bug was fixed and merged at 13 May 2017.

Marya
  • 64
  • 6
  • A link to a potential solution is always welcome, but please [add context around the link](//meta.stackoverflow.com/a/8259/169503) so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. Take into account that being _barely more than a link to an external site_ is a possible reason as to [Why and how are some answers deleted?](//stackoverflow.com/help/deleted-answers). – Waqar UlHaq Mar 07 '20 at 19:15