“Python Save 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()
Strange Skimmer

Как сохранить дикта в формате TXT

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

Python сохранить словарь как объект

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

Python Save Dictionary

import pickle

def Save():
    with open("Data.txt", "wb") as pkl_handle:
        pickle.dump(dictionary_data, pkl_handle)

# LOAD
def Load():
    with open("Data.txt", "rb") as pkl_handle:
        output = pickle.load(pkl_handle)
        return output

def Add_Value(Name, Amount):
    dictionary_data[Name] = Amount
    Save()

dictionary_data = Load()

Add_Value('Name', 'Value')

print(dictionary_data)
Lucky Llama

Ответы похожие на “Python Save Dictionary”

Вопросы похожие на “Python Save Dictionary”

Больше похожих ответов на “Python Save Dictionary” по Python

Смотреть популярные ответы по языку

Смотреть другие языки программирования