Character Encodings and display of strings
Leo.Kislov at gmail.com
Mon Nov 13 21:04:21 CET 2006
> It seemed to me that this sentence
> For many types, this function makes an attempt to return a string that
> would yield an object with the same value when passed to eval().
> might mean that the encoding setting of the source file might influence
> how repr represented the contents of the string. Nothing to do with
> Unicode. If a source file could have a declared encoding of, say,
> cp932 via the # coding comment, I thought there was a chance that eval
> would respond to that, too.
Not a chance :) Encoding is a property of an input/output object
(console, web page, plain text file, MS Word file, etc...). All
input/output object have specific rules determining their encoding,
there is absolutely no connection between encoding of the source file
and any other input/output object.
repr escapes bytes 128..255 because it doesn't know where you're going
to output its result so repr uses the safest encoding: ascii.
More information about the Python-list