shelf membership

John Machin sjmachin at lexicon.net
Sun Apr 1 02:22:20 CEST 2007


On Apr 1, 8:02 am, Aaron Brady <a... at uchicago.edu> wrote:
> can you shelve objects with membership?
>
> this gives you:
>
> TypeError: object does not support item assignment
> dict 0 True
> Exception exceptions.TypeError: 'object does not support item assignment'
> in  ignored
>
> > ignored is a bit mysterious.  tx in advance.
>
> from shelve import *
> class MyShelf(DbfilenameShelf):
>         def __init__(self, filename, flag='c', protocol=None,
> writeback=False, binary=None):
>                 self.__dict__['ready']=False
>                 DbfilenameShelf.__init__(self, filename, flag, protocol,
> writeback, binary)
>                 self.ready=True
>         def __setattr__(self,name,value):
>                 if not self.ready:
>                         self.__dict__[name]=value
>                 else:
>                         print name, value, self.ready
>                         self.__dict__[name]=value
>                         DbfilenameShelf.__setitem__(self,name,value)
>
> def open(filename, flag='c', protocol=None, writeback=False, binary=None):
>       return MyShelf(filename, flag, protocol, writeback, binary)

Please supply the *full* traceback, using copy/paste.




More information about the Python-list mailing list