1. 程式人生 > >UnicodeDecodeError: 'gbk' codec can't decode byte 0x9a in position 8: illegal multibyte sequence

UnicodeDecodeError: 'gbk' codec can't decode byte 0x9a in position 8: illegal multibyte sequence

with open('b1.s') as file_object:
	contents=file_object.read()
	print(contents)

報錯:
在這裡插入圖片描述原因:
讀取檔案中有中文
解決辦法:
開啟檔案時以utf-8格式開啟。

with open('b1.s',encoding='utf-8') as file_object:
	contents=file_object.read()
	print(contents)

總結:我是天才