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

  

上一篇:opencv-python(cv2)


下一篇:CCS工程使用VSCODE进行编写代码