UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 2: illegal multibyte sequence

时间:2023-01-04 20:48:45

Python 读写UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 2: illegal multibyte sequence 

字符流问题

open 的方式变为 二进制,也就是下面代码里的 open(filename,’rb’)

f = open('C:/Users/lenovo/Desktop/test.txt', 'rb')
print(f.read().decode('utf-8'))

f = open('C:/Users/lenovo/Desktop/test.txt', 'r')
print(f.read())