Python 将utf-8代码的字符串转换为真正的unicode字符串
现在我有了Python 将utf-8代码的字符串转换为真正的unicode字符串,python,string,unicode,Python,String,Unicode,现在我有了unicodecode-like“\u8fea\u514b”,如何将它转换为python中真正的unicode对象,比如u”\u8fea\u514b“。只需使用string.decode('unicode-escape') >>> s = "\u8fea\u514b" >>> type(s) <type 'str'> >>> s.decode('unicode-escape') u'\u8fea\u514b' # OR
unicode
code-like“\u8fea\u514b”
,如何将它转换为python中真正的unicode
对象,比如u”\u8fea\u514b“
。只需使用string.decode('unicode-escape')
>>> s = "\u8fea\u514b"
>>> type(s)
<type 'str'>
>>> s.decode('unicode-escape')
u'\u8fea\u514b'
# OR
>>> new_s = unicode(s, 'unicode-escape')
>>> type(new_s)
<type 'unicode'>
>>> new_s
u'\u8fea\u514b'
看医生从来都不痛-
class unicode(basestring)
| unicode(string [, encoding[, errors]]) -> object
|
| Create a new Unicode object from the given encoded string.
| encoding defaults to the current default string encoding.
>>> "\u8fea\u514b".decode('unicode-escape')
u'\u8fea\u514b'