python字典中显示中文

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python字典中显示中文相关的知识,希望对你有一定的参考价值。

#coding=utf-8
import json
dict={‘title‘:"这是中文"}
print json.dumps(dict,ensure_ascii=False,encoding="utf-8")

 

 

books=[
{‘name‘:u‘C#从入门到精通‘,‘price‘:23.7,‘store‘:u‘卓越‘},
{‘name‘:u‘C#从入门到精通二‘,‘price‘:44.5,‘store‘:u‘当当‘},
{‘name‘:u‘C#从入门到精通三‘,‘price‘:25.7,‘store‘:u‘新华书店‘},
{‘name‘:u‘C#从入门到精通四‘,‘price‘:25.8,‘store‘:u‘新华书店‘},
]
store=[]
for item in books:
for p in item:
if p==‘store‘:
store.append(item[p])
print json.dumps(store, ensure_ascii=False, encoding="utf-8")

 

["卓越", "当当", "新华书店", "新华书店"]















以上是关于python字典中显示中文的主要内容,如果未能解决你的问题,请参考以下文章

Python字典啥都不显示

在 Tkinter Python 中显示字典

Python2中解决列表,字典内汉字的显示问题

Python - 如何在 django 模板中为所有值并排显示两个键的字典值

Python:按多个条件显示排序字典

python-010-字典