字典數據dict
1 使用yaml保存
參考:http://www.cocoachina.com/articles/92667
# yaml安裝
conda install -c anaconda pyyaml
保存
import yaml
data = {
'key1': 1,
1: 2
}
with open('data.yml', 'w') as outfile:
yaml.dump(data, outfile, default_flow_style=False)
讀取
with open("data.yml", 'r') as stream:
data = yaml.load(stream)
print data[1] # 2
2 使用numpy保存
參考:https://blog.csdn.net/yangtf07/article/details/81571371
import numpy as np
# Save
dictionary = {'hello':'world'}
np.save('my_file.npy', dictionary)
# Load
read_dictionary = np.load('my_file.npy').item()
print(read_dictionary['hello']) # displays "world"