Re: Overriding iadd for dictionary like objects

2009-09-01 Thread RunThePun
On Sep 1, 3:00 am, a...@pythoncraft.com (Aahz) wrote: > In article > , > > > > > > RunThePun   wrote: > >On Aug 30, 10:33=A0pm, a...@pythoncraft.com (Aahz) wrote: > >> In article >.com>, > >> RunThePun =A0 wrote: > > >>>I

Re: Overriding iadd for dictionary like objects

2009-08-30 Thread RunThePun
On Aug 30, 10:33 pm, a...@pythoncraft.com (Aahz) wrote: > In article > , > > > > > > RunThePun   wrote: > > >I made a DictMixin where the keys are filenames and the values are the > >file contents. It was very simple and easy to do thanks to DictMixin. >

Re: Overriding iadd for dictionary like objects

2009-08-30 Thread RunThePun
e entire file back (__setitem__). The files are expected to be as big as 600 KB which will be appended 30 bytes at a time about 3 times a second. Performance-wise the system would probably work without open (..., 'ab') but it would be a real thrashing so the current solution uses a method "AddTo" as Robert suggested, sacrificing the neat getitem/setitem syntax. Just so I don't leave out any information, I actually also made a DirectoryDict for having multiple 'tables'. In this DictMixin, keys are directory names and values are FilesDict instances. So to write "European or African" to the file "/root/tmp/velocity" one would be just: >>> d = DirectoryDict("/root") >>> d["tmp"]["velocity"] = "European or African" So now I hope it's clearer why and how I wanted a special __item_iadd__ for the dictionary syntax, RunThePun -- http://mail.python.org/mailman/listinfo/python-list

Re: Overriding iadd for dictionary like objects

2009-08-26 Thread RunThePun
On Aug 27, 6:58 am, Robert Kern wrote: > On 2009-08-26 20:00 PM, Jan Kaliszewski wrote: > > > > > > > 27-08-2009 o 00:48:33 Robert Kern wrote: > > >> On 2009-08-26 17:16 PM, RunThePun wrote: > >>> I'd like to build a database wrapper using Dic

Overriding iadd for dictionary like objects

2009-08-26 Thread RunThePun
I'd like to build a database wrapper using DictMixin and allow items to be appended by my own code. The problem is += is always understood as setitem and getitem plainly. d = MyDict() d['a'] = 1 # this is the problem code that's I'd like to override. It's always setitem('a', getitem('a') + 3) d['