python 字典有序并写入json文件过程解析
作者:NotForget_On_The_Way 时间:2021-08-21 21:12:01
大致流程:
导包---import collections
新建一个有序字典---collections.OrderedDict()
写入json文件
代码:
import collections
real_result = collections.OrderedDict()
real_result["target"] = "total_result"
real_result["key1"] = "value1"
real_result["key2"] = "value2"
real_result["key3"] = "value3"
real_result_total = [real_result]
print real_result_total
输出:[OrderedDict([('target', 'total_result'), ('key1', 'value1'), ('key2', 'value2'), ('key3', 'value3')])]
current_dir = os.path.dirname(os.path.realpath(__file__))
path = os.path.join(os.path.join(current_dir, 'jsonfile'), result_json)
with open(path, 'w') as f:
json.dump(real_result_total, f, encoding="utf-8", ensure_ascii=False, indent=4, separators=(',', ':'))
json文件:
来源:https://www.cnblogs.com/pythonRoad/p/11612022.html
标签:python,字典,写入,json,文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MySQL时间字段究竟使用INT还是DateTime
2010-03-09 14:46:00
asp 输出换行的详细说明 原创
2011-02-24 11:15:00
Django压缩静态文件的实现方法详析
2023-06-15 05:31:33
YOLOv5构建安全帽检测和识别系统使用详解
2023-11-30 14:45:00
Python实现的自定义多线程多进程类示例
2023-11-16 08:52:15
跨浏览器的本地存储(一):userData behavior
2008-08-05 18:13:00
Python基础之字符串常见操作经典实例详解
2022-08-14 04:40:58
mysql 导入导出数据
2011-02-23 12:27:00
《Python之禅》中对于Python编程过程中的一些建议
2022-01-30 12:04:16
![](https://img.aspxhome.com/file/2023/3/72073_0s.jpg)
Sql Server2005对现有数据进行分区具体步骤
2008-06-26 13:18:00
c++生成dll使用python调用dll的方法
2023-02-16 11:40:05
DW自带的行为制作弹出菜单
2008-05-16 11:38:00
![](https://img.aspxhome.com/file/UploadPic/20072/200723113749490s.jpg)
python编程使用PyQt创建UE蓝图
2023-11-20 14:24:58
![](https://img.aspxhome.com/file/2023/0/64690_0s.gif)
详解Python如何获取列表(List)的中位数
2022-02-01 02:35:37
![](https://img.aspxhome.com/file/2023/0/86180_0s.png)
创建pycharm的自定义python模板方法
2021-01-11 04:46:41
Python selenium把歌词评论做成词云图
2022-12-29 10:17:35
![](https://img.aspxhome.com/file/2023/8/81648_0s.png)
sqlserver 索引的一些总结
2012-08-21 11:03:31
linux下安装apache与php;Apache+PHP+MySQL配置攻略
2023-11-14 15:43:46
Python 类的私有属性和私有方法实例分析
2021-06-18 05:13:47
php is_numberic函数造成的SQL注入漏洞
2023-07-18 00:32:25
![](https://img.aspxhome.com/file/2023/0/55450_0s.jpg)