Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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()
Comment

python save a dictionary as an object

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)
Comment

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)
Comment

PREVIOUS NEXT
Code Example
Python :: python program to find largest number in a list 
Python :: requests.Session() proxies 
Python :: python pyowm 
Python :: kivy change window size 
Python :: python run exe 
Python :: python numpy array size of n 
Python :: python get the last element from the list 
Python :: how to use h5 file in python 
Python :: try catch in python 
Python :: python convert images to pdf 
Python :: drop a list of index pandas 
Python :: python list remove at index 
Python :: pandas categorical to numeric 
Python :: pandas get value not equal to 
Python :: pandas dict from row 
Python :: python list transpose 
Python :: python replace nth occurrence in string 
Python :: python array get index 
Python :: docker django 
Python :: python loop go back to start 
Python :: discord.py reference 
Python :: how to run a python script 
Python :: python array append 
Python :: current date and time django template 
Python :: python start with 
Python :: django execute 
Python :: how to change case of string in python 
Python :: max in a list python 
Python :: python 3d array 
Python :: matplotlib display graph on jupyter notebook 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =