python模块之XlsxWriter
http://www.cnblogs.com/brightbrother/p/8671077.html
python2.X从json文件中读取数据进行unicode转码情况
方法一 str.decode('gb1312‘).encode('utf-8')
https://blog.csdn.net/sinat_41292836/article/details/81114826
方法2
需要从一个json文件中逐行读取数据并将数据写入到一个字典数据中。服务器上python版本为2.6直接使用json.load()函数时发现load到的数据都是经过unicode转码的数据每一项前边都会多一个“u`”导致后边程序无法获得字典的准确数据。
上网搜了半天解决方案,发现这是python2.x的固有机制,在python3中已经取消。在python3中直接使用json.load()是不会出现这种情况的,但是服务器上不好再装一个python3只能另找解决方案。找到可以用yaml模块解决该问题。
从pypi.python.org上下载pyaml模块并安装
安装后读取数据模块的程序内容是
#!/usr/bin/python
#-*- coding:utf-8 -*-
import json
import yaml
def resolveJson(fp,service_type):
for file_json in open(fp,'r'):
file_dict=yaml.safe_load(json.loads(file_json))#解决unicode转码问题
if service_type in ['rd','ns']:
if service_type == file_dict.keys()[0]:
icann_sla_result=file_dict[service_type]['downtime']
print 'la_numb='la_result
break
else:
print service_type ,"is error! "