python打印列表有中文乱码怎么解决?
来源:华佗小知识
定义列表并直接输出,结果输出结果中文是乱码:
e=['你好',1,'apple'] print e
输出结果:
['\xe4\xbd\xa0\xe5\xa5\xbd', 1, 'apple']
解决方法:
e=['你好',1,'apple'] print json.dumps(e,encoding='utf-8',ensure_ascii=False)
输出结果:
["你好", 1, "apple"]
更多Python知识请关注