19年3月学习总结-XlsxWriter-selenium-requests-urllib3-yaml

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! "

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huanghong6956

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值