file = open("file.txt") print file.readlines() file.close()
运行时报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position... 修改内容以下 将编码
file = open("file.txt")
修改成code
file = open("file.txt",encoding='utf-8')
便解决该问题。 “file = open("file.txt",encoding='utf-8')" #以指定的编码类型(即文件自己的编码)打开文件,chardet库能够判断文件编码类型utf-8