python2的字符编码问题

1. 将Unicode转为中文

1. 字符串.encode('utf8')
2. 字符串.encode('raw_unicode_escape')

对于字典里面的unicode

a = {u'information': u'\u521b\u5efa\u5931\u8d25\uff0c\u6570\u636e\u5df2\u5b58\u5728\uff0c\u8bf7\u52ff\u91cd\u590d\u63d0\u4ea4', u'code': u'2253-C'}
b = repr(a).decode('raw_unicode_escape')
print b

 

posted @ 2021-09-14 15:49  10132714  阅读(149)  评论(0编辑  收藏  举报