Re: Overriding iadd for dictionary like objects

2009-09-01 Thread Aahz
In article <7f82416a-53be-41b3-9503-1492454cc...@upsg2000gro.googlegroups.com>, RunThePun wrote: >On Sep 1, 3:00=A0am, a...@pythoncraft.com (Aahz) wrote: >> In article .com>, >> RunThePun =A0 wrote: >>>On Aug 30, 10:33=3DA0pm, a...@pythoncraft.com (Aahz) wrote: In article ups=3D >>>.com>, >>

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 made a DictMixin where the keys are filenames and the values are the > >>>f

Re: Overriding iadd for dictionary like objects

2009-08-31 Thread Aahz
In article , RunThePun wrote: >On Aug 30, 10:33=A0pm, a...@pythoncraft.com (Aahz) wrote: >> In article .com>, >> RunThePun =A0 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. >>> >>>For e

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. > > >For example this code writes "abc" in a

Re: Overriding iadd for dictionary like objects

2009-08-30 Thread Aahz
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. > >For example this code writes "abc" in a file named "temp.txt" and >prints the contents of the file named "swallow", the

Re: Overriding iadd for dictionary like objects

2009-08-30 Thread Jan Kaliszewski
PS. Sorry for sending 2 posts -- the latter is the correct one. Cheers, *j -- http://mail.python.org/mailman/listinfo/python-list

Re: Overriding iadd for dictionary like objects

2009-08-30 Thread RunThePun
On Aug 29, 1:58 pm, Carl Banks wrote: > On Aug 28, 10:37 pm, Joshua Judson Rosen wrote: > > > > > > > Carl Banks writes: > > > > On Aug 28, 2:42 pm, Terry Reedy wrote: > > > > > Carl Banks wrote: > > > > > I don't think it needs a syntax for that, but I'm not so sure a method > > > > > to modif

Re: Overriding iadd for dictionary like objects

2009-08-29 Thread Carl Banks
On Aug 28, 10:37 pm, Joshua Judson Rosen wrote: > Carl Banks writes: > > > On Aug 28, 2:42 pm, Terry Reedy wrote: > > > > Carl Banks wrote: > > > > I don't think it needs a syntax for that, but I'm not so sure a method > > > > to modify a value in place with a single key lookup wouldn't > > > >

Re: Overriding iadd for dictionary like objects

2009-08-29 Thread Steven D'Aprano
On Sat, 29 Aug 2009 01:23:59 -0400, Joshua Judson Rosen wrote: > Robert Kern writes: >> >> On 2009-08-28 16:42 PM, Terry Reedy wrote: >> > Carl Banks wrote: >> > >> > > I don't think it needs a syntax for that, but I'm not so sure a >> > > method to modify a value in place with a single key looku

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Joshua Judson Rosen
Carl Banks writes: > > On Aug 28, 2:42 pm, Terry Reedy wrote: > > > Carl Banks wrote: > > > I don't think it needs a syntax for that, but I'm not so sure a method > > > to modify a value in place with a single key lookup wouldn't > > > occasioanally be useful. > > > > Augmented assignment does th

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Joshua Judson Rosen
Robert Kern writes: > > On 2009-08-28 16:42 PM, Terry Reedy wrote: > > Carl Banks wrote: > > > > > I don't think it needs a syntax for that, but I'm not so sure a > > > method to modify a value in place with a single key lookup > > > wouldn't occasioanally be useful. > > > > Augmented assignment d

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Carl Banks
On Aug 28, 2:42 pm, Terry Reedy wrote: > Carl Banks wrote: > > I don't think it needs a syntax for that, but I'm not so sure a method > > to modify a value in place with a single key lookup wouldn't > > occasioanally be useful. > > Augmented assignment does that. Internally uses two lookups, one

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Robert Kern
On 2009-08-28 16:42 PM, Terry Reedy wrote: Carl Banks wrote: I don't think it needs a syntax for that, but I'm not so sure a method to modify a value in place with a single key lookup wouldn't occasioanally be useful. Augmented assignment does that. No, it uses one __getitem__ and one __set

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Terry Reedy
Carl Banks wrote: I don't think it needs a syntax for that, but I'm not so sure a method to modify a value in place with a single key lookup wouldn't occasioanally be useful. Augmented assignment does that. For instance: def increment(value): return value+1 d = { 'a': 1 } d

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Carl Banks
On Aug 26, 11:49 pm, RunThePun wrote: > Anybody have any more ideas? I think python should/could havev a > syntax for overriding this behaviour, i mean, obviously the complexity > of supporting all operators with the getitem syntax could introduce > alot of clutter. But maybe there's an elegant so

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Aahz
In article <21e57363-4e92-41cb-9907-5aef96ad0...@o15g2000yqm.googlegroups.com>, RunThePun wrote: > >Anybody have any more ideas? I think python should/could havev a >syntax for overriding this behaviour, i mean, obviously the complexity >of supporting all operators with the getitem syntax could i

Re: Overriding iadd for dictionary like objects

2009-08-27 Thread Robert Kern
On 2009-08-27 01:49 AM, RunThePun wrote: Anybody have any more ideas? I think python should/could havev a syntax for overriding this behaviour, i mean, obviously the complexity of supporting all operators with the getitem syntax could introduce alot of clutter. But maybe there's an elegant solut

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 DictMixin and allow items > >>> to be appended by my own

Re: Overriding iadd for dictionary like objects

2009-08-26 Thread Robert Kern
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 DictMixin and allow items to be appended by my own code. The problem is += is always understood as setitem and getitem pl

Re: Overriding iadd for dictionary like objects

2009-08-26 Thread Jan Kaliszewski
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 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 p

Re: Overriding iadd for dictionary like objects

2009-08-26 Thread Jan Kaliszewski
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 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 p

Re: Overriding iadd for dictionary like objects

2009-08-26 Thread Xavier Ho
I haven't tested it, but did you encounter a problem defining __iadd__ in the class definition? See: http://docs.python.org/reference/datamodel.html#object.__iadd__ Cheers, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xav

Re: Overriding iadd for dictionary like objects

2009-08-26 Thread Robert Kern
On 2009-08-26 17:16 PM, RunThePun wrote: 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'

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['