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

Leif K-Brooks eurleif at ecritters.biz
Tue Dec 27 12:06:06 CET 2005


Chris Song wrote:
> Here's my solution
> 
> _unicodeRe = re.compile("(\\\u[\da-f]{4})")
> def unisub(mo):
> 	return unichr(int(mo.group(1)[2:],16))
> 
> unicodeStrFromNetwork = '\u5927'
> unicodeStrNative = _unicodeRe(unisub, unicodeStrFromNetwork)
> 
> But I think there must be a more straightforward way to do it.



>>> '\u5927'.decode('unicode_escape')
u'\u5927'



More information about the Python-list mailing list