Kenneth McDonald wrote:
> Given a Python unicode character (string of length one), how would I
> find out the \uXXXX escape sequence for it? This isn't obvious from the
> docs I've been looking through.

You can use the ord builtin, or the encode method with
"unicode_escape":

>>> a = u'\u1234'
>>> a
u'\u1234'
>>> print a
ሴ
>>> ord(a)
4660
>>> hex(ord(a))
'0x1234'
>>> a.encode('unicode_escape')
'\\u1234'


Carl Banks

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to