Python 3.0 and repr

Mark Tolonen M8R-yfto6h at mailinator.com
Sun Sep 28 20:58:28 EDT 2008


""Martin v. Löwis"" <martin at v.loewis.de> wrote in message 
news:48dffb54$0$1082$9b622d9e at news.freenet.de...
>> 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

Thanks Martin, it's clear now.  I just read about the new ascii() function 
before seeing your reply.

> 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".

I just picked that example out of the air.  I study Chinese and knew it was 
a character in that area of the Unicode map.  My usual editors (PythonWin 
and PyAlaMode from wxPython) don't work with Python 3, which was why I was 
using the Windows cmd prompt.

Thanks,
Mark 




More information about the Python-list mailing list