By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,102 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

Getting unicode escape sequence from unicode character?

P: n/a
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.

Thanks,
Ken
Dec 27 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

Dec 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.