菜鸟新手,使用的是python2.7,转码一直报错AttributeError: 'file' object has no attribute 'decode'
转码代码是:
import chardet
from sys import argv
script, filename = argv
ready = open(filename, "r+")
print chardet.detect(ready.read())
print (ready.decode('windos-1252')).encode('unicode')
一直报错,unicode改成 utf- 8和 gbk也不行,请问各位大神这是哪里出问题了
ready是file,
ready.read()是文件内容.
decode之后就是uniccode,不要尝试encode成为unicode
chardet判断的可能性只有不到30%,文件可能比较小.结果不准确.