“Python Save Dictionary para arquivar” Respostas de código

como salvar o dict em formato txt

dict = {'Python' : '.py', 'C++' : '.cpp', 'Java' : '.java'}
f = open("dict.txt","w")
f.write( str(dict) )
f.close()
Vivacious Vole

Python Save Dictionary para arquivar

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)
Zealous Zebra

Python Escreva um dicionário para arquivar

dictionary = {'someKey' : 'someValue'}
file_path = 'somePathToFile/someFileName.py'
with open(file_path, 'w') as output_file:
    print(dictionary, file=output_file)
HAL's therapist

Python salve um dicionário como um objeto

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)
Exuberant Earthworm

Respostas semelhantes a “Python Save Dictionary para arquivar”

Perguntas semelhantes a “Python Save Dictionary para arquivar”

Procure respostas de código populares por idioma

Procurar outros idiomas de código