python处理utf8编码中文及打印中文列表和字典的方法
python处理utf8编码中文,需要在py文件的第一行加入:# -*- coding:utf-8 -*- 或 #coding=utf-8打印字符串时,使用print str.encode('utf8');
打印中文列表时,使用循环 for key in list:print key
打印中文字典时,可以使用循环,也可以使用json:
import json
print json.dumps(dict, encoding='UTF-8', ensure_ascii=False)
以上介绍的是python的小知识点,有时遇上utf8编码中文无所适从时,刚好用上。
页:
[1]