comment enregistrer le dict au format txt
dict = {'Python' : '.py', 'C++' : '.cpp', 'Java' : '.java'}
f = open("dict.txt","w")
f.write( str(dict) )
f.close()
Vivacious Vole
dict = {'Python' : '.py', 'C++' : '.cpp', 'Java' : '.java'}
f = open("dict.txt","w")
f.write( str(dict) )
f.close()
with open('saved_dictionary.pkl', 'wb') as f:
pickle.dump(dictionary, f)
with open('saved_dictionary.pkl', 'rb') as f:
loaded_dict = pickle.load(f)
dictionary = {'someKey' : 'someValue'}
file_path = 'somePathToFile/someFileName.py'
with open(file_path, 'w') as output_file:
print(dictionary, file=output_file)
import pickle
dictionary_data = {"a": 1, "b": 2}
# SAVE
with open("data.pkl", "wb") as pkl_handle:
pickle.dump(dictionary_data, pkl_handle)
# LOAD
with open("data.pkl", "rb") as pkl_handle:
output = pickle.load(pkl_handle)
print(output)