[New-bugs-announce] [issue13997] Add open_ascii() builtin
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)
title: Add open_ascii() builtin
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce