[Tutor] associating two objects without ORM and processing a text file

neubyr neubyr at gmail.com
Fri Feb 15 04:01:20 CET 2013

On Wed, Feb 13, 2013 at 1:55 PM, Alan Gauld <alan.gauld at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130214/5ac95e09/attachment.html>

More information about the Tutor mailing list