Python2 transcoding error problem

A rookie uses python2.7, transcoding to keep reporting AttributeError: "file" object has no attribute" decode"
the transcoding code is:
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")

keep reporting errors, not even changing unicode to utf- 8 and gbk. May I ask you what"s wrong with this?

Mar.25,2021

ready is file,
ready.read () is the file content.

  

ready is a file object, which does not have an encode method. What you need is to read out the contents of the file, assign a variable to it, and then guess the encoding. 30% of the possibility is too small, indeed not very accurate.

Menu