python persistence

castironpi at gmail.com castironpi at gmail.com
Tue Apr 1 13:47:33 CEST 2008


On Apr 1, 12:16 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Tue, 01 Apr 2008 00:48:35 -0300, <castiro... at gmail.com> escribió:
>
> > We do have, but on Windows, file is not locked to multi-tasking,
> > shelve.  But why don't we have types in there, or non-string
> > primitives in keys?
>
> >>>> c= shelve.open( 'temp', 'c' )
> >>>> c['0']= 'a'
> >>>> c.sync()
> >>>> del c
> >>>> c= shelve.open( 'temp', 'c' )
> >>>> c['0']
> > 'a'
>
> >>>> c['0'].append( 0 )
> >>>> c['0']
> > []
>
> The above session doesn't make sense unless it's somewhat related to "on  
> Windows, file is not locked to multi-tasking," and another process has  
> modified the database in-between. I don't think the problem is restricted  
> to Windows only. There exist file locking mechanisms.
>
> > And why don't primitive mutations modify contents of disk?  A
> > metaquestion.
>
> They do, if you pass writeback=True to the shelve constructor, but read  
> the docs.
> shelve is a simple class; if it can't fulfill your needs, you may want to  
> use a relational database (perhaps with an ORM like SQLObjects or  
> SQLAlchemy) or an object database like ZODB or Durus.
>
> >>>> c['0']= type('None',(),{})
> > Traceback (most recent call last):
> > pickle.PicklingError: Can't pickle <class '__main__.None'>: it's not
> > found as __main__.None
>
> Don't do that then. Or use the available pickle hooks to customize how  
> such classes may be pickled. All persistence mechanisms have limitations.
>
> --
> Gabriel Genellina

I don't see a problem with that; except that binaries come from
disks.  You could have a Python session that runs entirely on disks +
the ALU.  I want to know if any, and correct me here, simple
modification can store live objects.  I call a.append(it) and the
memory update takes place on disk instead.

If you require that all objects referenced by on-disk objects be on-
disk, that's an easy workaround.



More information about the Python-list mailing list