原来代码如下
#coding=utf-8
testF1= open("testFi.txt","r")
for line in testF1:
print(line)
结果出现错误
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 42: illegal multibyte sequence
改成
#coding=utf-8
testF1= open("testFi.txt","rb")
for line in testF1:
print(line)
出现错误
b'\xe4\xbc\x98\xe7\xbe\x8e\xe8\x83\x9c\xe4\xba\x8e\xe4\xb8\x91\xe9\x99\x8b\r\n'
b'\xe6\x98\x8e\xe4\xba\x86\xe8\x83\x9c\xe4\xba\x8e\xe9\x9a\x90\xe6\x99\xa6\r\n'
b'\xe7\xae\x80\xe6\xb4\x81\xe8\x83\x9c\xe4\xba\x8e\xe5\xa4\x8d\xe6\x9d\x82'
改成
testF1= open("testFi.txt","r",encoding='UTF-8')
for line in testF1:
print(line)
结果正确
优美胜于丑陋
明了胜于隐晦
简洁胜于复杂