Python读取txt中的汉字报错:UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa7 in position 4: illegal multibyte sequence
举例:
file='E:/0_MyWork/python_programm/children_name/strich7.txt'
with open(file, "r") as file_7strich:
each_line_7strich=file_7strich.readlines()
print(1)
解决办法:在open中加入 encoding='utf-8’即可
file='E:/0_MyWork/python_programm/children_name/strich7.txt'
with open(file, "r", encoding='utf-8') as file_7strich:
each_line_7strich=file_7strich.readlines()
print(1)