Answers for "pickle save dictionary python"

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
-1

save a file as a pickle

with open('mypickle.pickle', 'wb') as f:
    pickle.dump(some_obj, f)

# note that this will overwrite any existing file
# in the current working directory called 'mypickle.pickle'
Posted by: Guest on February-27-2020
1

write data to using pickle

import pickle

example_dict = {1:"6",2:"2",3:"f"}

pickle_out = open("dict.pickle","wb")
pickle.dump(example_dict, pickle_out)
pickle_out.close()
Posted by: Guest on May-27-2020
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

Python Answers by Framework

Browse Popular Code Answers by Language