import pickle object = Object() filehandler = open(filename, 'w') pickle.dump(object, filehandler)
Here is what the above code is Doing:
1. We create an object of the class Object.
2. We open a file in write mode.
3. We dump the object into the file.
Now, let’s see how to load the object from the file.