[Python-3000] Pre-PEP: Easy Text File Decoding
solipsis at pitrou.net
Sun Sep 10 16:04:47 CEST 2006
Le dimanche 10 septembre 2006 à 14:52 +0100, David Hopwood a écrit :
> > On the other hand "autotextfile('myfile.txt', by_content=True)" would
> > enable content-based guessing, thus be equivalent to Paul's
> > "encoding='guess'".
> As I pointed out earlier, any file open function that guesses the encoding
> should return which encoding has been guessed.
Since open files are objects, the encoding can just be a read-only
# replace autotextfile by whatever API is finally chosen ;)
f = autotextfile('myfile.txt', by_content=True)
enc = f.encoding
> Alternatively, it could be possible to allow the encoding to be set
> after the file has been opened, in which case a separate function
> could do the guessing.
Yes, sounds like a nice alternative.
More information about the Python-3000