[New-bugs-announce] [issue13997] Add open_ascii() builtin

Nick Coghlan report at bugs.python.org
Sun Feb 12 05:33:07 CET 2012


New submission from Nick Coghlan <ncoghlan at gmail.com>:

(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)

----------
messages: 153164
nosy: ncoghlan
priority: normal
severity: normal
status: open
title: Add open_ascii() builtin

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13997>
_______________________________________


More information about the New-bugs-announce mailing list