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

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 :: bee movie script 
Python :: ticks font size matplotlib 
Python :: dataframe from two series 
Python :: python multiply list by scalar 
Python :: pg double slider 
Python :: python convert png to jpg 
Python :: join list with comma python 
Python :: matplotlib label axis 
Python :: how to install python3 in ubuntu 
Python :: desktop background change with python 
Python :: python read file delete first line 
Python :: rectangle in tkinter 
Python :: how to get the current position of mouse on screen using python 
Python :: make first row columns pandas 
Python :: concat dataFrame without index reset 
Python :: How do I set Conda to activate the base environment by default? 
Python :: split a path into all subpaths 
Python :: generate python date list 
Python :: df.drop index 
Python :: pandas count specific value in column 
Python :: tkinter load image 
Python :: python turtle line thickness 
Python :: flask minimal install 
Python :: python blender select object by name 
Python :: python print float with 2 decimals 
Python :: tkinter max size 
Python :: import matplotlib.pyplot as plt 
Python :: how to append to every second item in list python 
Python :: generate a list of random non repeated numbers python 
Python :: best games made in pygame 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =