Encoding error in Jupyter when %run another notebook

独自空忆成欢 提交于 2019-12-12 18:17:41

问题


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?


回答1:


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:"


来源:https://stackoverflow.com/questions/43915006/encoding-error-in-jupyter-when-run-another-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!