Wait... WHAT?

Chris Angelico rosuav at gmail.com
Thu Feb 13 04:47:07 CET 2014

On Thu, Feb 13, 2014 at 2:29 PM, Tim Chase
<python.list at tim.thechases.com> wrote:
> My original point (though
> perhaps not conveyed as well as I'd intended) was that only bytes get
> written to the disk, and that some encoding must take place.  It can
> be done implicitly using some defaults which may break (as demoed),
> whereas one would be better off doing it explicitly such as Chris
> shows

And since the default encoding varies based on matters outside your
script (most notably platform - I tried this on Windows and Linux, and
got a default of UTF-8 on Linux and CP-1252 on Windows; but
environment variables and such can interfere too), I would say that
omitting the encoding= parameter should be done ONLY when you actually
have no idea what the encoding is, only that it's "probably something
from the rest of the system". And, well, if that's what you're looking
at, you definitely can't trust to reading or writing non-ASCII (you
can probably trust ASCII). When you create a file that you'll read
back yourself, specify an encoding.


More information about the Python-list mailing list