Using pickle module

The pickle module is used to serialize and de-serialize the data available in collections like and dictionary

Use dump() function to save data from memory to the disc in some file (serialization)
Use load() function load data from disc to memory (de-serialization)


>>> names=["Vikas","Kapil","Neeraj"]
>>> names
['Vikas', 'Kapil', 'Neeraj']

>>> import pickle
>>> f1=open("names","wb")
>>> pickle.dump(names,f1)
>>> f1.close()

>>> f2=open("names","rb")
>>> mynames=pickle.load(f2)
>>> f2.close()

>>> mynames
['Vikas', 'Kapil', 'Neeraj']
>>> names==mynames
True


Comments

Popular posts from this blog

Converting Excel File to JSON File using xlrd module

Using Oracle with Python

Using time module