# -*- coding utf-8 -*-
import json
import os
m = {
"message": str("hello")
}
if not os.path.exists('test.json'): # 不存在就创建
print("create new file")
with open('test.json', 'w') as json_file:
json_file.write(json.dumps(m, sort_keys=True))
else: # 存在直接打开
print("exists")
with open('test.json') as json_file:
print(json.load(json_file))
Python读写json文件
最新推荐文章于 2024-07-27 01:09:47 发布