[Tips] python 字典 保存

也可以使用numpy

import numpy as np

# Save
dictionary = {'hello':'world'}
np.save('file.npy', dictionary) 

# Load
read_dictionary = np.load('file.npy').item()
print(read_dictionary['hello']) 

  

或是pickle

def save_obj(obj, fileName):
with open('{}.pkl'.format(fileName), 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)

def load_obj(fileName):
with open('{}.pkl'.format(fileName), 'rb') as f:
return pickle.load(f)

  

posted @ 2020-03-16 10:57  虚无真仙  阅读(335)  评论(0编辑  收藏  举报