我一直在使用一个程序来处理滴答数据。 最近它开始处理文件时就停止工作并崩溃。 看起来供应商呈现数据的方式有所改变。
所以我们说我只是运行:
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.
更多推荐
发布评论