[Python-3000] Displaying strings containing unicode escapes

Oleg Broytmann phd at phd.pp.ru
Sat May 3 22:36:17 CEST 2008


On Sat, May 03, 2008 at 10:20:43PM +0200, "Martin v. L?wis" wrote:
> > On Sat, May 03, 2008 at 09:54:24AM +0900, Atsuo Ishimoto wrote:
> >> If requirement for ASCII-repr is popular enough, we can provide a
> >> built-in function like this:
> >>
> >> 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;
there is a chance .encode() after repr() will escape or unescape the result
in a wrong way. 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.

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-3000 mailing list