读写json
#数据保存如json文件
import json
jsObj = json.dumps(code_sec) fileObject = open('jsonFile.json', 'w')
fileObject.write(jsObj)
fileObject.close()
#读取json文件
# 将类文件对象中的JSON字符串直接转换成 Python 字典
with open('jsonFile.json', 'r', encoding='utf-8') as f:ret_dic = json.load(f)print(type(ret_dic)) # 结果 <class 'dict'>print(ret_dic) # 结果 pengjunlee
ret_dic
读写txt
a = [1,3,4,5,6,7,8,9]
with open('a.txt', 'w') as f: json.dump(a, f)
with open('a.txt', 'r') as f: a = json.load(f)
print(a)