Answers for "python save and load dictionary"

5

save and load a dictionary python

import pickle
dictionary_data = {"a": 1, "b": 2}
a_file = open("data.pkl", "wb")
pickle.dump(dictionary_data, a_file)
a_file.close()
a_file = open("data.pkl", "rb")
output = pickle.load(a_file)
print(output)
a_file.close()
Posted by: Guest on March-27-2021
2

how to save dict in txt format

dict = {'Python' : '.py', 'C++' : '.cpp', 'Java' : '.java'}
f = open("dict.txt","w")
f.write( str(dict) )
f.close()
Posted by: Guest on May-27-2020
0

save python dic

import pickledict = {'Python' : '.py', 'C++' : '.cpp', 'Java' : '.java'}f = open("file.pkl","wb")pickle.dump(dict,f)f.close()
Posted by: Guest on April-27-2020

Code answers related to "python save and load dictionary"

Python Answers by Framework

Browse Popular Code Answers by Language