python 将dictionary 转化成json并且写入和读取json文件
2021-01-29 14:16
标签:并且 json lin highlight with dump code print user python 将dictionary 转化成json并且写入和读取json文件 标签:并且 json lin highlight with dump code print user 原文地址:https://www.cnblogs.com/ufovsuso/p/12832023.html 1 import json
2
3 #将数据存入json文件 name:[gender,age,password]
4 user_dict = {"tracy": ["female",16,"123456"],
5 "bella": ["female",17,"password"],
6 "colin": ["male",18,"colin"]
7 }
8 #写入json文件
9 with open(‘userinfo.json‘, ‘w‘) as json_file:
10 json.dump(user_dict, json_file)
11 #读取json文件并打印
12 with open(‘userinfo.json‘, ‘r‘) as json_file:
13 load_dict = json.load(json_file)
14 print(load_dict["tracy"])
上一篇:快速排序的ES6实现
下一篇:Java JUC
文章标题:python 将dictionary 转化成json并且写入和读取json文件
文章链接:http://soscw.com/index.php/essay/48721.html