Python doesn't really listen to the environment when it comes to reading and writing files in a particular encoding. It only listens to the environment when it comes to encoding unicode written to stdout, if stdout is connected to a terminal.
When reading and writing files in Python 2.x, you deal with bytestrings (the str
type) by default. They're encoded data. You have to decode the data you read by hand, and encode what you want to write. Or you can use codecs.open()
to open the files, which will do the encoding for you.
In Python 3.x, you open files either in binary mode, in which case you get bytes
, or you open it in text mode, in which case you should specify an encoding just like with codecs.open()
in Python 2.x.
None of these are affected by environment variables; you either read bytes, or you specify the encoding.