[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)

浙公网安备 33010602011771号