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

查看:32
本文介绍了错误!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天全站免登陆