how to convert string like '\u5927' to unicode string u'\u5927'

Chris Song fakechris at
Tue Dec 27 11:27:35 CET 2005

Here's my solution

_unicodeRe = re.compile("(\\\u[\da-f]{4})")
def unisub(mo):
	return unichr(int([2:],16))

unicodeStrFromNetwork = '\u5927'
unicodeStrNative = _unicodeRe(unisub, unicodeStrFromNetwork)

But I think there must be a more straightforward way to do it.

More information about the Python-list mailing list