tensorflow学习——json数据保存及读取

1、glob

import glob 
# 返回文件夹下所有的py文件
f = glob.glob('tf\*.py')  # cifar10\__init__.py

2、json

import json

data1 = {'b':789,'c':456,'a':123}
data2 = {'a':123,'b':789,'c':456}
# 按关键字排序
d1 = json.dumps(data1,sort_keys=True)
d2 = json.dumps(data2)
d3 = json.dumps(data2,sort_keys=True)
# indent表示每行缩进9
d4 = json.dumps(data1,sort_keys=True,indent=9)

# writing json data
with open('data.json', 'w') as f:
    json.dump(d1, f)
# reading data back
with open('data.json', 'r') as f:
    data = json.load(f)

你可能感兴趣的:(tensorflow学习——json数据保存及读取)