test.py
file='u8.html' # utf8编码的文件
text=open(file).read()
命令行运行 python3.exe test.py
提示
UnicodeDecodeError: 'gbk' codec can't decode bytes in position 2-3: illegal multibyte sequenc
修改为text=open(file, 'r', encoding='utf-8').read() 不报错了
print(text) 再输出一下
提示变成了
UnicodeEncodeError: 'gbk' codec can't encode character '\ufeff' in position 0: illegal multibyte sequence
怎么样在console输出utf8编码的文件的内容呢?
file='u8.html' # utf8编码的文件
text=open(file).read()
命令行运行 python3.exe test.py
提示
UnicodeDecodeError: 'gbk' codec can't decode bytes in position 2-3: illegal multibyte sequenc
修改为text=open(file, 'r', encoding='utf-8').read() 不报错了
print(text) 再输出一下
提示变成了
UnicodeEncodeError: 'gbk' codec can't encode character '\ufeff' in position 0: illegal multibyte sequence
怎么样在console输出utf8编码的文件的内容呢?