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 dictionary to file

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

save python dic

import pickledict = {'Python' : '.py', 'C++' : '.cpp', 'Java' : '.java'}f = open("file.pkl","wb")pickle.dump(dict,f)f.close()
Comment

PREVIOUS NEXT
Code Example
Python :: python replace backslash with forward slash 
Python :: array of random integers python 
Python :: django versatileimagefield 
Python :: normalize values between 0 and 1 python 
Python :: pysimplegui double Slider 
Python :: python how to get project location 
Python :: run django app locally 
Python :: tkinter change label text color 
Python :: write a python program to read last n lines of a file 
Python :: python how to set the axis ranges in seaborn 
Python :: flask run app reset on change 
Python :: change directory in python os 
Python :: how to make a python exe 
Python :: frequency count of values in pandas dataframe 
Python :: STandardScaler use example 
Python :: python how to get number of strings in a list 
Python :: python randomise between 0 or 1 
Python :: python copy file 
Python :: flask install 
Python :: autoclicker in python 
Python :: how to draw image in tkinter 
Python :: .fill pygame 
Python :: how to update pandas 
Python :: extract first letter of column python 
Python :: python float till 2 decimal places 
Python :: how to extract data from website using beautifulsoup 
Python :: next prime number in python 
Python :: import NoSuchKey in boto3 
Python :: count how many duplicates python pandas 
Python :: how to install nltk 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =