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

Ganesan Rajagopal rganesan at myrealbox.com
Tue Dec 27 06:07:23 EST 2005


>>>>> "Chris" == Chris Song <fakechris at gmail.com> writes:

> 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)

How about unicodeStrNative = eval("u'%s'" % (unicodeStrFromNetwork,))

Ganesan

-- 
Ganesan Rajagopal (rganesan at debian.org) | GPG Key: 1024D/5D8C12EA
Web: http://employees.org/~rganesan        | http://rganesan.blogspot.com





More information about the Python-list mailing list