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