python创建文件并写入json

python创建文件并写入json

import json
import os
import uuid

PATH = 'D:/SecurityData'
if not os.path.exists(PATH):
    os.makedirs(PATH)

fw = open('{}/Security.json'.format(PATH), 'a+')
fr = open('{}/Security.json'.format(PATH), 'r')
fw.write(json.dumps({
    'name': 'user_name',
    'uuid': str(uuid.uuid1())
}, ensure_ascii=False) + '\n')
fw.flush()

你可能感兴趣的:(python,python)