讀寫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)