Learn Python Pickle
What is Python Pickle
Pickle is a module. A python object is called a pickle, which has become a byte string.
This is an example of an object-oriented programming environment.
In other words , as tememl in the basic pickle event, we can say that byte arrays can be sent to another machine on the network and used again there.
An object converted to byte string with pickle can be saved to a file, moved to another machine, placed in the database, network upset,sent to another location.
Pickle files are the most commonly used place for picke. the pickle file contains the conversion of an Ensign to pickle. pickle files are easily used to store temporary results , to use them as input to another Python program , and to backup them. In the pickle module , the dump() method is used to put the object in the pickle file , and the load() method is used to call the object in the pickle file.
To write and read the pickel files, please note that ‘b’ (binary) access mode is required as in binary files.
Learn Python Pickle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | > > > import pickle > > > colors = {"red" , "blue", " Yesil" } >>> pickle.dump colors, open ("trial.p", " wb")) > > > colors = pickle.load (open ("trial.p", " rb"))) > > colors {'red', 'blue', 'green' } import pickle # send dictionary pick file to dict1 dict1 = {'a' : 1 , 'b' : 2,' c ' = 3} d = open ("letters.pkl", " wb") pickle.dump (dict1, D) d.close() # pickle file data from 2 dictionary sites u=open ("letters.pkl", " rb") dict2 = pickles.load (u) finish.close printing (dict1) {'a' : 1 , 'b' : 2 , 'c' = 3} printing (dict2) {'a' : 1 , 'b' : 2 , 'c' = 3} |