changes to shelf items fail silently?

eichin at metacarta.com eichin at metacarta.com
Mon Mar 17 23:56:20 EST 2003


> They're mutating the returned list (to which you retain no
> references, and which therefore is immediately discarded).

Ah, so I'm missing the distinction that it's returning a list, and not
being a reference to one.  (Knowable only by looking at the code to
shelve, since the syntax hides it, right?)

> You want *every* change to the object to cause the shelve to be
> updated immediately?  Really?

I certainly want every change to happen to the in-memory copy, which
was what alerted me to the problem; having a sync() to flush it out to
disk would suffice.  But yes, in this particular case I do want live
changes.  If it were large, using a real database might make sense,
but only *after* benchmarking shelve and finding it slow, which I
don't expect to :-)

(Note that I'm coming from perl, and would have done this with a tie'd
hash there.)

> That's pretty hard in general, since the shelve-like thing can't
> know a priori what operations mutate an object and what operations
> don't.  (It could make an effort to detect changes after the fact

Or just pass back wrapped-objects, whose methods are "like" the input
type but commit themselves on __setitem__ calls?

In the meantime, I've worked around it with explicit stores, but
eventually will want something cleaner.




More information about the Python-list mailing list