错误! blahfile不是UTF-8编码的.储存已停用 [英] Error! blahfile is not UTF-8 encoded. Saving disabled

查看:340
本文介绍了错误! blahfile不是UTF-8编码的.储存已停用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我试图实际上是从网上编写一个gzip文件,但为简化起见,我写了一些非常基本的测试.

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()

它运行的很好,我在Jupyter中看到它已经在目录列表中创建了test.txt.gz文件.因此,我单击它时期望有一大堆指示二进制文件的垃圾字符,就像在记事本中看到的那样.
但是,相反,我得到了这个...

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

这让我想,哦,天哪,编码错误,我的编码有问题,我的保存,我可以保存字节吗?我是否使用正确的例程?然后花5个小时尝试所有代码和模块的组合.

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.

推荐答案

一个非常简单的答案就是以上都不是.这是一条非常令人误解的错误消息,尤其是当您编写的代码旨在保存带有怪异扩展名的二进制文件时.

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

因此,请转到文件资源管理器",在Finder中导航到刚刚保存的文件并打开它.瞧! 一切都按计划进行,没有错误.

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.

希望这可以节省其他人的大量调试时间,请Jupyter更改您的错误消息.

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

这篇关于错误! blahfile不是UTF-8编码的.储存已停用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆