Answers for "Save a Dictionary to File in Python Using the dump Function of the pickle Module"

1

save a dict to pickle

import pickle

a = {'hello': 'world'}

with open('filename.pickle', 'wb') as handle:
    pickle.dump(a, handle, protocol=pickle.HIGHEST_PROTOCOL)

with open('filename.pickle', 'rb') as handle:
    b = pickle.load(handle)
Posted by: Guest on August-11-2021
0

Save a Dictionary to File in Python Using the dump Function of the pickle Module

import pickle

my_dict = { 'balls': 4, 'halles': 2, 'mango': 6, 'Grapes': 11}

with open("myDictionary.pkl", "wb") as tf:
    pickle.dump(my_dict,tf)
Posted by: Guest on October-11-2021

Code answers related to "Save a Dictionary to File in Python Using the dump Function of the pickle Module"

Python Answers by Framework

Browse Popular Code Answers by Language