首页 > 其他 > 详细

字典读写训练

时间:2020-07-21 15:51:11      阅读:75      评论:0      收藏:0      [点我收藏+]

字典写入json文件中:

import json
stu_mark={}
stu_mark["Name"]=input("Name=")
stu_mark["English"]=float(input("English="))
stu_mark["Music"]=float(input("Music="))
stu_mark["Chinese"]=float(input("Chinese="))
print(stu_mark)
# with open("stu_mark.json", mode=‘w‘, encoding=‘utf-8‘) as fp:
#     json.dump(stu_mark, fp,ensure_ascii=False,indent=2)
f=open("stu_mark.json",w,encoding=utf-8)
json.dump(stu_mark,f,False,2)
f.close()

从json文件读入到字典中:

import json

# with open("stu_mark.json", mode=‘r‘, encoding=‘utf-8‘) as fp:
#     print(json.load(fp))
f=open("stu_mark.json",r,encoding=utf-8)
stu_mark=json.load(f)
print(type(stu_mark))
print(stu_mark)
f.close()

 

字典读写训练

原文:https://www.cnblogs.com/exesoft/p/13354273.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!