import json
class OperationJson(object):
def __init__(self,file_name=None):
if file_name:
self.file_name=file_name
else:
self.file_name='E:/python/requests/dataconfig/request.json'
self.data=self.read_data()
#读取json文件,并将其反序列化为python对象
def read_data(self):
with open(self.file_name) as fp:
data=json.load(fp)
return data
#根据关键字获取数据
def get_data(self,id):
return self.data[id] if __name__=='__main__':
js=OperationJson()
print(js.get_data('login'))

python操作json文件的更多相关文章

  1. python操作json文件获取内容

    写case时,将case 写到json文件比写到,写python一定要学会处理json 以下,是要处理的json 处理操作包括:打开json文件,获取json文件内容,关闭json文件,读取内容中的对 ...

  2. Python 3 操作json 文件

    背景 json 是一种轻量级的数据交换格式.易于人阅读和编写,同时也易于机器解析和生成. 一般表现形式是一个无序的 键值对 的集合. 资料: 官方文档: https://docs.python.org ...

  3. Python操作Zip文件

    Python操作Zip文件 需要使用到zipfile模块 读取Zip文件 随便一个zip文件,我这里用了bb.zip,就是一个文件夹bb,里面有个文件aa.txt. import zipfile # ...

  4. linux 操作 json文件

    Linux 下 操作 json 文件神器 jq.  jq yum install jq -y 查看一个 file.json 文件 # jq . file.json JSON (JavaScript O ...

  5. python操作txt文件中数据教程[4]-python去掉txt文件行尾换行

    python操作txt文件中数据教程[4]-python去掉txt文件行尾换行 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文章 python操作txt文件中数据教程[1]-使用pyt ...

  6. python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件

    python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 python操作txt文件中 ...

  7. python操作txt文件中数据教程[2]-python提取txt文件

    python操作txt文件中数据教程[2]-python提取txt文件中的行列元素 觉得有用的话,欢迎一起讨论相互学习~Follow Me 原始txt文件 程序实现后结果-将txt中元素提取并保存在c ...

  8. python操作txt文件中数据教程[1]-使用python读写txt文件

    python操作txt文件中数据教程[1]-使用python读写txt文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 原始txt文件 程序实现后结果 程序实现 filename = '. ...

  9. python操作json来存储简单的数据,pickle来操作复杂的数据

    json作为不同语言间进行数据交互的媒介,在当下已经渐渐取代了之前的xml,看一波python操作json # coding = ascii import json import pickle imp ...

随机推荐

  1. 通过pip3安装ipython

    操作系统:Centos7.4:ipython可以用来测试python语句,故需要安装. 首先需要安装epelde的扩展库: easy_install是由PEAK(Python Enterprise A ...

  2. uva 512

    1. 问题 不知道怎么存储操作 看代码注释,else if等 2. 代码 #include <iostream> #include <stdio.h> #include < ...

  3. C笔试题(一)

    a和b两个整数,不用if, while, switch, for,>, <, >=, <=, ?:,求出两者的较大值. 答案: int func(int a, int b) { ...

  4. CSS 布局_如何实现容器中每一行的子容器数量随着浏览器宽度的变化而变化?

    实现一个浮动布局,红色容器中每一行的蓝色容器数量随着浏览器宽度的变化而变化,就如下图: 要实现这样一个布局,我们首先需要如下的 HTML: <div id="float-contain ...

  5. jquery选择器中的find和空格,children和>的区别、及父节点兄弟节点,还有判断是否存在的写法

     一.find和空格,children和>及其它的区别   空格:$('parent childchild')表示获取parent下的所有的childchild节点(所有的子孙). 等效成  = ...

  6. 1.1 xss原理分析与剖析(2)

    0×01 反射型XSS: 反射XSS是XSS分类中最多的,他们原理是下面这样: Hacker——发现存在反射XSS的URL——根据输出点的环境构造XSS代码——进行编码.缩短(可有可无,是为了增加迷惑 ...

  7. product of大数据平台搭建------CM 和CDH安装

    一.安装说明 CM是由cloudera公司提供的大数据组件自动部署和监控管理工具,相应的和CDH是cloudera公司在开源的hadoop社区版的基础上做了商业化的封装的大数据平台. 采用离线安装模式 ...

  8. hdu1088

    #include <stdio.h> #include <string.h> int main() { char s[10000]; int len; int cnt = 0; ...

  9. hdu1084

    #include<iostream> #include<algorithm> using namespace std; #define N 101 struct node { ...

  10. Django 之 logging

    1. logging 1.1 什么是 logging logging 模块是 Python 内置的日志管理模块,不需要额外安装. 使用: import logging logging.critical ...