常用模块:
一个python文件就是一个模块
1、标准模块,python自带的
2、第三方模块,需要安装
3、自己写的python文件
json,就是一个字符串
1.json转为字典
json_str = '''
{"name":"xiaohei","age":18,"sex":"男","age":18}
'''
res = json.loads(json_str) #把字符串(json串)转成字典
2.字典转为json串
dic={"name":"xiaohei","age":18,"sex":"男","age":18}
res=json.dumps(dic,ensure_ascii=False,indent=4)
3.自己读
f = open('user.json',encoding='utf-8')
json.load(f)
4.自己写
fw = open('newuser.json','w',encoding='utf-8')
dic={"name":"xiaohei","age":18,"sex":"男","age":18}
json.dump(dic,fw,indent=4,ensure_ascii=False)