In article <[email protected]>,
Ned Batchelder <[email protected]> wrote:
> In Python3, repr() will return a Unicode string, and will preserve existing
> Unicode characters in its arguments. This has been controversial. To get
> the Python 2 behavior of a pure-ascii representation, there is the new
> builtin ascii(), and a corresponding %a format string.
I'm still stuck on Python 2, and while I can understand the controversy ("It
breaks my Python 2 code!"), this seems like the right thing to have done. In
Python 2, unicode is an add-on. One of the big design drivers in Python 3 was
to make unicode the standard.
The idea behind repr() is to provide a "just plain text" representation of an
object. In P2, "just plain text" means ascii, so escaping non-ascii characters
makes sense. In P3, "just plain text" means unicode, so escaping non-ascii
characters no longer makes sense.
Some of us have been doing this long enough to remember when "just plain text"
meant only a single case of the alphabet (and a subset of ascii punctuation).
On an ASR-33, your C program would print like:
MAIN() \(
PRINTF("HELLO, ASCII WORLD");
\)
because ASR-33's didn't have curly braces (or lower case).
Having P3's repr() escape non-ascii characters today makes about as much sense
as expecting P2's repr() to escape curly braces (and vertical bars, and a few
others) because not every terminal can print those.
--
Roy Smith
[email protected]
--
https://mail.python.org/mailman/listinfo/python-list