For example:
file1.py
import pickle class Test: A = '' B = '' f = open('pickle','w+') ob = Test() ob.A = 'A' ob.B = 'B' pickle.dump(ob, f)
file2.py
import pickle class Test: pass f = open('pickle','r+') ob = '' # If we don't have class template for loading object, # the error will occur. ob = pickle.load(f) print ob.A # output: A
It's very simple in python to save state of the object ^^.
More detail at: http://docs.python.org/library/pickle.html
No comments:
Post a Comment