【Python】UnicodeDecodeError: gbk codec can not decode byte 0xa7 in position 8: illegal multibyte

516 ワード

エラー:UnicodeDecodeError:'gbk'codec can't decode byte 0 xa 7 in position 8:illegal multibyte
エラーメッセージ:
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 8: illegal multibyte 

エラーの原因:
with open('space list.txt', 'r') as f:
    for line in f.readlines():

解決方法:
with open('space list.txt', 'r',encoding='UTF-8') as f:
    for line in f.readlines():