Python学习笔记 --- python实现修改json文件
2023-09-27 14:27:48 时间
基本原理就是通过读取文件,将json数据读取出来,然后进行修改,再写回文件中。
# -*- coding:utf-8 -*-
import json
def process_json(input_json_file, output_json_file):
file_in = open(input_json_file, "r")
file_out = open(output_json_file, "w")
# load数据到变量json_data
json_data = json.load(file_in)
print json_data
print "after update --->"
print type(json_data)
# 修改json中的数据
json_data["job"] = "hahah"
print json_data
# 将修改后的数据写回文件
file_out.write(json.dumps(json_data))
file_in.close()
file_out.close()
process_json("../jsonfile/mysql2hive_templet.json","../jsonfile/mysql2hive_instance.json")
相关文章
- Python数据处理 | 批量提取文件夹下的csv文件,每个csv文件根据列索引提取特定几列,并将提取后的数据保存到新建的一个文件夹
- 【Python从入门到精通】(十九)Python对文件的读写操作一览表,非常实用,非常简单
- python学习笔记(文件、上下文管理器、print()方法的的补充)
- 【Python开发】python重命名文件和遍历文件夹操作
- 【Python开发】python读写文件,和设置文件的字符编码比如utf-8
- 【Python开发】python读写文件,和设置文件的字符编码比如utf-8
- Python常用函数:open文件读写【文本文件:处理的基本单元是“字符”】【二进制文件(图片、音频、视频):处理的基本单元是“字节”】
- 使用python删除N天前的文件(2)
- python 之文件 编码问题
- 为python编译使用GPU版本的Dlib
- Python学习笔记之Centos6.9安装Python3.6
- python matplotlib键盘鼠标事件学习
- python打包程序为exe文件
- Python文件操作函数os.open、io.open、内置函数open之间的关系
- 第7章 Python类型、类、协议目录
- 第9.8节 Python使用writelines函数写入文件内容
- docker:从零开始部署一个python的hello world并debug(其他语言同理)
- python图像处理(图像平移)
- Python Numpy random.pareto() 帕累托分布
- Python pipenv使用。pipenv环境如何与pycharm绑定
- python脚本 pyqt 打包成windows可执行exe文件 pyinstaller