python3 写入中文文件时,提示UnicodeDecodeError: 'gbk' codec can't decode byte 0xa8 in position 14: illegal

提示信息为:
Traceback (most recent call last):
File “read_tyxt”, line 6, in
lines = file_object.readlines()
UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa8 in position 14: illegal multibyte sequence

解决:
1、导入codecs包
2、open指定文件类型
如下:
import codecs

file_name = ‘test.txt’

with open(file_name,encoding = ‘utf_8’) as file_object:

你可能感兴趣的:(python,导入中文文件编码问题解决)