Is unicode_escape broken?

mtnBikingMark at mtnBikingMark at
Tue Dec 13 21:29:44 CET 2005


I am confused by unicode_escape functionality - it doesn't  seem to
follow string_escape functionality.

I would expect that given the same string (or at least a non-unicode
and unicode string appropriately) that they would produce more or less
the same output, but:

>>> "\t\\t".encode('string_escape')
>>> u"\t\\t".encode('unicode_escape')

(I would have expected "\\t\\\\t" )

and then round - tripping also seems to be broken for unicode_escape:
>>> "\t\\t".encode('string_escape').decode('string_escape')
>>> u"\t\\t".encode('unicode_escape').decode('unicode_escape')

Python Version "Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310
32 bit (Intel)] on win32"


More information about the Python-list mailing list