这是一个GPS log文件,编码方式看sublimetext显示是windows-1252格式
][1]
我想读取这个文件一行打印用下面代码:
#!user/bin/python3 fin=open('gpsdebug.log.20100101000042.c','rt',encoding="windows-1252") lines = fin.readline() fin.close() print(lines)
提示报错:
Traceback (most recent call last): File "strline.py", line 8, in lines = fin.readline() File "/usr/lib/python3.5/encodings/cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 3504: character maps to
不知道问题出在哪里?
补充:
删除文本文档中一部分乱码字符可以正常读取,如果不处理这些字符有办法跳过吗?
fin=open('gpsdebug.log.20100101000042.c','rt',encoding="windows-1252",
errors='ignore'
)