美文网首页
python显示'\u201di'类似的unicode编码

python显示'\u201di'类似的unicode编码

作者: 潇湘demi | 来源:发表于2020-05-06 18:33 被阅读0次

1.print '\u201d'.decode('unicode_escape')

2.在使用json.dumps时要注意一个问题

import json

print json.dumps('中国')"

输出的会是

'中国' 中的ascii 字符码,而不是真正的中文。

这是因为json.dumps 序列化时对中文默认使用的ascii编码.想输出真正的中文需要指定ensure_ascii=False

# -*- coding: utf-8 -*-

from __future__import unicode_literals

import json

jsondata = json.dumps(dicdata,sort_keys=True,indent=4,ensure_ascii=False)

print jsondata

print type(json.dumps(dicdata))

相关文章

网友评论

      本文标题:python显示'\u201di'类似的unicode编码

      本文链接:https://www.haomeiwen.com/subject/clfgghtx.html