[Python-ideas] Python 3 open() text files: make encoding parameter optional for cross-platform scripts

MRAB python at mrabarnett.plus.com
Sat Jun 8 21:43:12 CEST 2013


On 08/06/2013 19:02, Stephen J. Turnbull wrote:
> MRAB writes:
>
>   > 'open' defaults to universal newline support when opening for
>   > reading (though that's not possible when opening for writing!), and
>   > it would be nice if it also defaulted to a 'universal' encoding,
>   > i.e. UTF-8.
>
> There's no such thing as a universal encoding.  Unicode is a
> universal character set in the sense that it can encode all
> characters, but there is no universal encoding that can be used to
> decode all texts.
>
I didn't say "universal encoding", I said "'universal' encoding". :-)

What I meant was that I'd prefer it to default to an encoding that was
the same on all platforms, not whatever encoding _this_ machine happens
to be using, which might be different from whatever encoding _that_
machine happens to be using.

Or, in summary, I think that portability is more important.

> If the OS's default encoding is not UTF-8, then you can and should bet
> that most files on that system will not be in UTF-8.  That's still
> true today.  Few users will be made happy by a Python that forces them
> to do something special to read files in the default encoding.
>
It would be the default encoding only for the machine on which it was
created. If I moved the file to another machine, however, I could get
mojibake.

> The real question is why your system's default encoding is something
> that makes you unhappy, isn't it?
>



More information about the Python-ideas mailing list