expanding persistant objects

Moshe Zadka moshez at math.huji.ac.il
Mon Mar 27 21:23:42 CEST 2000

On Mon, 27 Mar 2000, Pete Shinners wrote:

> i'm learning python here and have a question about storing
> persistant objects. i plan to keep a real simple list of
> users and i want to know the best way to simple store it
> and reload it.
> my only concern is that later i'll probably want to add
> more fields to each users record. can simple pickling
> handle this? do i need to use one of the DB storage
> libraries?

Try using shelve, using classes for users. Have a version number
in your class that marks the version, and if later versions have
a really new way of storing records, override the __setstate__ method.

> i'm worried if i start saving the data one way, when i go
> to add extra fields i wont be able to load the files anymore.

Pickle (and hence shelve) were designed to deal with this.
Moshe Zadka <mzadka at geocities.com>. 
http://www.linux.org.il -- we put the penguin in .com

More information about the Python-list mailing list