Author ncoghlan
Recipients ncoghlan
Date 2012-02-12.04:33:06
SpamBayes Score 1.28149e-06
Marked as misclassified No
Message-id <1329021187.19.0.262146289648.issue13997@psf.upfronthosting.co.za>
In-reply-to
Content
(This proposes a new builtin, so may need to become a PEP)

A common programming task is "I want to process this text file, I know it's in an ASCII compatible encoding, I don't know which one specifically, but I'm only manipulating the ASCII parts so it doesn't matter".

In Python 2, you handle that task by doing:

    f = open(fname)

The non-ASCII parts are then carried along as 8-bit bytes and reproduced faithfully when written back out.

In Python 3, you handle it by doing:

    f = open(fname, encoding="ascii", errors="surrogateescape")

The non-ASCII parts are then carried along as code points in the Unicode Private Use Area and reproduced faithfully when written back out.

It would be significantly more friendly to beginners (and migrants from Python 2) if the following shorthand spelling was available out of the box:

    f = open_ascii(fname)
History
Date User Action Args
2012-02-12 04:33:07ncoghlansetrecipients: + ncoghlan
2012-02-12 04:33:07ncoghlansetmessageid: <1329021187.19.0.262146289648.issue13997@psf.upfronthosting.co.za>
2012-02-12 04:33:06ncoghlanlinkissue13997 messages
2012-02-12 04:33:06ncoghlancreate