Tutorial on Python Pickling

Posted in Uncategorized

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

In a previous tutorial, we created an instance of Person and Student class. You can serialize this object into a file with the pickle module…

This write the john object data in binary form to “person.dat”.

You can de-serialize it into a python object like …

You get back the john object by opening the data file as “read binary” and running pickle.load.

For security reasons, never read from an untrusted data source and deserialize it into a python object. It may do things that you may not intend.

So to serialize, pickle.dump()
To de-serialize, pickle.load()

For serialization of python data structures into json, you can use jsonpickle module.


Related Posts

Tags

Share This