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

Nick Coghlan ncoghlan at gmail.com
Sun Jun 9 16:10:03 CEST 2013


On 9 June 2013 23:13, Yuval Greenfield <ubershmekel at gmail.com> wrote:
> On Sun, Jun 9, 2013 at 2:24 PM, Chris Angelico <rosuav at gmail.com> wrote:
>>
>> On Sun, Jun 9, 2013 at 9:09 PM, anatoly techtonik <techtonik at gmail.com>
>> wrote:
>> > I can not agree with your generic priorities in approach to application
>> > desing, which are:
>> > 1. Program should be able to read 3rd-party files produced on the same
>> > system
>> > 2. Program should be able to read its own files on any system
>> >
>> > My choice is 2 then 1.
>>
>> #2 is easily achieved: just provide a specific encoding. It's your
>> program, so you can control what it writes.
>>
>
> Both are easily achieved.
>
> The discussion is about open()'s default, implicit behavior. I'm in favor of
> #2 with utf-8 because it's consistent, easing python collaboration across
> platforms, and does the right thing. Albeit an opinionated thing.

There is no discussion to be had, as the default is not going to
change. The decision to favour local system compatibility over cross
platform consistency was made long ago and is no longer open to
negotiation.

In a distributed environment where all the systems are correctly to
use UTF-8, then Python's default makes no difference (you will get
UTF-8 either way). If systems are NOT configured to use UTF-8, then
Python must choose between compatibility with other applications on
that system and with Python installations on other systems that may be
configured differently. If people don't want the system encoding, then
they have to be explicit about the encoding they want, ensuring
cross-platform consistency *regardless* of Python's default.

Regards,
Nick.

--
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list