[Python-3000] Displaying strings containing unicode escapes

"Martin v. Löwis" martin at v.loewis.de
Sat May 3 22:57:06 CEST 2008


>>>> def repr_ascii(obj):
>>>>     return str(repr(obj).encode("ASCII", "backslashreplace"), "ASCII")
>>>    It is hard to apply the function for repr(container).
>>> repr(container).encode("unicode_escape") is the only way (at least I don't
>>> see any other way).
>> I think Atsuo envisioned you to invoke "repr_ascii(container)".
> 
>    Who knows what are string representations of the objects in container;

I know: it's a Unicode object.

> there is a chance .encode() after repr() will escape or unescape the result
> in a wrong way.

No, there is no such chance.

> I do not insist on anything (I think printable repr() and
> repr().encode("unicode_escape") satisfy my needs) so I'm just pointing
> there could be a problem; don't know how important it is.

I don't think there is one (except that any repr_ascii function should
also *decode* its result back into a string before returning it).

Regards,
Martin


More information about the Python-3000 mailing list