1import pickle
2file_name='my_file.pkl'
3f = open(file_name,'wb')
4pickle.dump(my_data,f)
5f.close()
1import pickle
2
3pickle.dump( favorite_color, open( "save.p", "wb" ) )
4favorite_color = pickle.load( open( "save.p", "rb" ) )
1import pickle
2# load : get the data from file
3data = pickle.load(open(file_path, "rb"))
4# loads : get the data from var
5data = pickle.load(var)
1import pickle
2# dump : put the data of the object in a file
3pickle.dump(obj, open(file_path, "wb"))
4# dumps : return the object in bytes
5data = pickle.dump(obj)
1import pickle
2
3example_dict = {1:"6",2:"2",3:"f"}
4
5pickle_out = open("dict.pickle","wb")
6pickle.dump(example_dict, pickle_out)
7pickle_out.close()