Python 3.0 and repr

"Martin v. Löwis" martin at v.loewis.de
Sun Sep 28 17:47:00 EDT 2008


> What are others' opinions?  Any insight to this design decision?

The intention is that all printable characters in a string get displayed
in repr. This was in particular requested by Japanese users (but also by
other users of non-ASCII characters) which complained that repr() is
fairly useless if your strings actually contains *no* ASCII characters
(but all of them are printable).

Notice that repr() of the string actually succeeds; try

>>> x='\u5000'
>>> z=repr(x)

It is the printing of the repr that fails.

> Maybe repr() should always display the ASCII representation with
> escapes for all other characters

You can use the ascii() builtin if you want that.

> especially considering the "repr() should produce output suitable for
> eval() when possible" rule.

But that is preserved under the new behavior, also! Just try

py> x='\u5000'
py> eval(repr(x))==x
True

Regards,
Martin

P.S. How did you manage to get U+5000 into your data, on a system where
the terminal encoding is cp437? Google translates it as "Rash"; the
Unihan database also has "bewildered", "wildly".



More information about the Python-list mailing list