Error! blahfile is not UTF-8 encoded. Saving disabled

生来就可爱ヽ(ⅴ<●) 提交于 2020-07-09 12:00:26

问题


So, I'm trying to write a gzip file, actually from the net, but to simplify I wrote some very basic test.

import gzip
LINES = [b'I am a test line' for _ in range(100_000)]
f = gzip.open('./test.text.gz', 'wb')
for line in LINES:
    f.write(line)
f.close()

It runs great, and I can see in Jupyter that it has created the test.txt.gz file in the directory listing. So I click on it expecting a whole host of garbage characters indicative of a binary file, like you would see in Notepad.
However, instead I get this ...

Error!  test.text.gz is not UTF-8 encoded.
Saving disabled.
See console for more details

Which makes me think, oh my god, coding error, something is wrong with my encoding, my saving, can I save bytes ? Am I using the correct routines ?? And then spend 5 hours trying all combinations of code and modules.


回答1:


The very simple answer to this is none of the above. This is a very misleading error message, especially when the code you've written was designed to save a binary file with a weird extension.

What this actually means is ...

    I HAVE NO IDEA HOW TO DISPLAY THIS DATA ! - Yours Jupyter

So, go to your File Explorer, Finder navigate to the just saved file and open it. Voila !! Everything worked exactly as planned, there is no error.

Hope this saves other people many hours of debugging, and please Jupyter, change your error message.



来源:https://stackoverflow.com/questions/61114350/error-blahfile-is-not-utf-8-encoded-saving-disabled

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