On Wed, Feb 13, 2013 at 1:55 PM, Alan Gauld <alan.ga...@btinternet.com>wrote:
> On 13/02/13 19:14, neubyr wrote: > > I am not sure how to save an object in memory to a file >> before exiting the program. Any examples or related documentation links >> would be really helpful. I am guessing it would be using some kind of >> before teardown method, but not sure about it. Any help? >> > > If using class methods or standalone functions just call them explicitly > at the start and end of your program. If you want to > be sure it gets called use a try/finally > > try: > Book.loadBooks(filename) # load the data > # do your program stuff > finally: > Book.saveBooks(filename) # save the data > > That ensures that even if there is an exception the data will always be > saved. > > > Thanks Alan! - N
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor