Python将list中的unicode转换成中文显示

有这样一个列表:

list = [{‘channel_id‘: -3, ‘name‘: u‘\u7ea2\u5fc3\u5146\u8d6b‘}, {u‘seq_id‘: 0, u‘name_en‘: u‘Personal Radio‘, u‘channel_id‘: 0, u‘abbr_en‘: u‘My‘, u‘name‘: u‘\u79c1\u4eba\u5146\u8d6b‘}]
1

其中name值是中文,如何讲其显示为中文?

s = str(self.channel_list).replace(‘u\‘‘,‘\‘‘)
print s.decode("unicode-escape")
1
2

成功显示:

[{‘channel_id‘: -3, ‘name‘: ‘红心兆赫‘}, {‘seq_id‘: 0, ‘name_en‘: ‘Personal Radio‘, ‘channel_id‘: 0, ‘abbr_en‘: ‘My‘, ‘name‘: ‘私人兆赫‘}, ]
1

但此时类型为unicode

>>> type(s)
<type ‘unicode‘>
1
2

————————————————
版权声明:本文为CSDN博主「Muge_」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/cc7756789w/article/details/46049369

原文地址:https://www.cnblogs.com/qiumingcheng/p/11792858.html

时间: 2024-08-06 08:00:02

Python将list中的unicode转换成中文显示的相关文章

python将dict中的unicode打印成中文

python将dict中的unicode打印成中文 import json a = {u'content': {u'address_detail': {u'province': u'\u5409\u6797\u7701', u'city': u'\u957f\u6625\u5e02', u'street_number': u'', u'district': u'', u'street': u'', u'city_code': 53}, u'point': {u'y': u'43.89833761

JAVA unicode转换成中文

/** * * unicode 转换成 中文 * @param theString * @return */ public static String decodeUnicode(String theString) { char aChar; int len = theString.length(); StringBuffer outBuffer = new StringBuffer(len); for (int x = 0; x < len;) { aChar = theString.char

unicode 转换成中文

+ (NSString *)replaceUnicode:(NSString *)unicodeStr { NSString *tempStr1 = [unicodeStr stringByReplacingOccurrencesOfString:@"\\u" withString:@"\\U"]; NSString *tempStr2 = [tempStr1 stringByReplacingOccurrencesOfString:@"\"&q

Python3的unicode编码转换成中文问题

Python3的unicode编码转换成中文问题 从别的地方搬过来的,担心以后不容易搜索到,就收集过来. 我当时面临的问题是要从C++发json代码出来,用python写了个server,然后返回给C++程序,结果收到的是:httpSvrDataCbUser: {"tranNO": "0808ad498670dc996", "data": "\u65b0A1EY16", "ver": "1.0&q

djnago unicode 转换成str list

from django.core.serializers.json import DjangoJSONEncoder group_name = puppet_host.objects.filter(ip=ip).values_list('host_group',flat=True) g_name = json.dumps(list(group_name), cls=DjangoJSONEncoder) unicode 转换成list definitions_list = [definition.

用python做采集时相对路径转换成绝对路径

采集时,有时候需要采集图片,但某些网站的图片提供的相对地址,最好转换成绝对地址 在scrapy中有如下的解决策略 http://stackoverflow.com/questions/6499603/python-scrapy-convert-relative-paths-to-absolute-paths http://stackoverflow.com/questions/19970015/scrapy-item-loader-to-get-a-absolute-url-from-extra

新手学习算法----二叉树(将一个二叉查找树按照中序遍历转换成双向链表)

题目:将一个二叉查找树按照中序遍历转换成双向链表. 给定一个二叉查找树: 4 / 2 5 / 1 3 返回 1<->2<->3<->4<->5. 思路:如果对于当前节点,把右子树转换成双向链表,然后把左子树转换成双向链表,转换的时候我们都标记了链表的头节点和尾节点,那么只需要将当前节点和左子树的尾部相连,和右子树的头部相连即可. Java代码:这个是借鉴九章里面的解题法.但是对于左右子树转换成二叉树也不是很理解,还待需要继续分析. /** * Definit

字符串转换:字符串中的&#39;aa&#39;转换成&#39;bb&#39;,但是如果是&#39;a&#39;、&#39;aaa&#39;等,则不进行转换

代码: public void transferString(String str) { //0.条件初始化 char[] cArr = str.toCharArray(); //将字符串转为字符数组处理 char[] flagArr = new char[cArr.length]; //字符数组标记,判断是否转换 for(int i = 0; i < flagArr.length; i++) { //字符数组初始为0 flagArr[i] = '0'; } //1.循环遍历数组,每次处理一个或

python 实现 全角字符 传转换成 半角字符串

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> def strQ2B(ustring): #把全角字符串转半角 ustring=ustring.decode("cp9