Python无法解码字符集(Python can't decode a character set)

编程入门 行业动态 更新时间:2024-10-27 05:23:08
Python无法解码字符集(Python can't decode a character set)

我一直在使用一个程序来处理滴答数据。 最近它开始处理文件时就停止工作并崩溃。 看起来供应商呈现数据的方式有所改变。

所以我们说我只是运行:

with open("N:\\2017\\2017-09-28 Daily.CAP") as f: i = 0 while True: c = f.read(1)

我得到这个错误:

Traceback (most recent call last): File "C:/Users/b.karjoo/Documents/PycharmProjects/untitled1/test.py", line 4, in <module> c = f.read(1) File "C:\Users\b.karjoo\py3_virt_env\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 1799: character maps to <undefined>

有什么建议么?

I've been using a program to process tick data. Recently it stopped working and crashed as soon as it starts processing the file. It seems that something has changed with how the vendor renders the data.

So let's say I simply run:

with open("N:\\2017\\2017-09-28 Daily.CAP") as f: i = 0 while True: c = f.read(1)

I get this error:

Traceback (most recent call last): File "C:/Users/b.karjoo/Documents/PycharmProjects/untitled1/test.py", line 4, in <module> c = f.read(1) File "C:\Users\b.karjoo\py3_virt_env\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 1799: character maps to <undefined>

Any suggestions?

最满意答案

我希望这能解决问题

with open(filename, encoding="cp437") as file:

但是,如果你的文件的编码类型不是cp437,除此之外,如果你使用notepad ++来查看你的文件,你可以通过点击来检查它的编码类型

编码,它将显示编码的类型。

如果你使用崇高的文字去

查看 - >显示控制台

在底部view.encoding()键入字段,它将为您提供编码类型。

I hope this will resolve the issue

with open(filename, encoding="cp437") as file:

But if your file's encoding type is not cp437 and something else apart from that and if your using notepad++ to view your file, you can check its encoding type by clicking on

Encoding, which will show the type of encoding.

If your using sublime text go to

View -> Show Console

Type into field at bottom view.encoding() and it will give you the encoding type.

更多推荐

本文发布于:2023-07-26 19:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1280287.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符集   Python   decode   set   character

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!