expanding persistant objects

Jean-Claude Wippler jcw at equi4.com
Tue Mar 28 00:22:28 CEST 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?
> 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.

That's why the MetaKit database engine does on-the-fly restructuring:

Example one:
  import Mk4py
  db = Mk4py.Storage('data.mk',1)
  vw = db.getas('people[name:S,age:I]')

Example two:
  import Mk4py
  db = Mk4py.Storage('data.mk',1)
  vw = db.getas('people[name:S,age:I,city:S]')
  for r in vw:
    r.city = 'Hollywood'
  for r in vw.sort():
    print r.name, r.age, r.city

If you run one first, and then two, you'll have restructured on the fly.
It'll be instant, regardless of the number of rows.  If for any reason
the transaction is not completed, then neither will the restructure.

-- Jean-Claude

More information about the Python-list mailing list