UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xad in position 3: illegal multibyte sequence

一、原代码:

#By yangbo 2020.08.11
tf =open("12.txt","rt")
print(tf.readline())
tf.close()

当我输入代码去运行时,然后出错了:

help(open)一下:open( )函数默认的enconding =None,所以默认是不能够读取到中文的;得加上encoding="utf-8"


二、修改后的代码:

#By yangbo 2020.08.11
tf =open("12.txt","rt",encoding='utf-8')
print(tf.readline())
tf.close()

猜你喜欢

转载自blog.csdn.net/qq_38689263/article/details/107927327