Is unicode_escape broken?

mtnBikingMark at gmail.com mtnBikingMark at gmail.com
Tue Dec 13 21:29:44 CET 2005


Hi,

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')
'\\t\\\\t'
>>> u"\t\\t".encode('unicode_escape')
'\\t\\t'

(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')
'\t\\t'
>>> u"\t\\t".encode('unicode_escape').decode('unicode_escape')
u'\t\t'

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

Thanks
    Mark




More information about the Python-list mailing list