survey: is shelve broken? should it be fixed?

holger krekel pyth at devel.trillke.net
Tue May 7 18:16:23 EDT 2002


Alex Martelli wrote:
> On Tuesday 07 May 2002 21:28, Bjorn Pettersen wrote:
> 	...
> > +1 if it also prints 2 as the result of the last expression below (and
> > if it remains 2 after I close and re-open the shelve):
> > >>> import shelve
> > >>> s = shelve.open('ciao','c')
> > >>> class Foo:
> >
> > ...   def __init__(self, x):
> > ...     self.x = x
> > ...
> >
> > >>> class Bar:
> >
> > ...   def __init__(self, y):
> > ...     self.y = y
> > ...
> >
> > >>> s['bye'] = Foo(Bar(1))
> > >>> s['bye'].x.y = 2
> > >>> s['bye'].x.y
> >
> > 1
> >
> >
> > Seems like a "real" OODBMS might be the only thing that would count as
> > unsurprising in this case though?
> 
> That's what I see using my patch (corrected for a bug after I posted it to 
> sf):
> 
> [alex at lancelot Lib]$ python
> Python 2.2.1 (#1, Apr 15 2002, 17:55:14)
> [GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import shelve
> >>> s=shelve.open('ciao','c',smart=1)
> >>> class Foo:
> ...   def __init__(self, x): self.x=x
> ...
> >>> class Bar:
> ...   def __init__(self, y): self.y=y
> ...
> >>> s['bye']=Foo(Bar(1))
> >>> s['bye'].x.y=2
> >>> s['bye'].x.y
> 2
> >>> s.close()
> >>> s=shelve.open('ciao','c',smart=1)
> >>> s['bye'].x.y
> 2
> >>>

Might i ask whether you read my suggestion to
implement the "smart"-switch at the global module level?

    holger





More information about the Python-list mailing list