Re: Overriding iadd for dictionary like objects

2009-09-01 Thread Aahz
In article b11a8a0e-03ca-41c9-b0d0-c5180b6a2...@p15g2000vbl.googlegroups.com, RunThePun ubershme...@gmail.com wrote: On Aug 30, 10:33=A0pm, a...@pythoncraft.com (Aahz) wrote: In article e09276e8-8152-4002-8366-4c12705a8...@l35g2000vba.googlegroups= .com, RunThePun =A0ubershme...@gmail.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 b11a8a0e-03ca-41c9-b0d0-c5180b6a2...@p15g2000vbl.googlegroups.com, RunThePun  ubershme...@gmail.com wrote: On Aug 30, 10:33=A0pm, a...@pythoncraft.com (Aahz) wrote: In article

Re: Overriding iadd for dictionary like objects

2009-09-01 Thread Aahz
In article 7f82416a-53be-41b3-9503-1492454cc...@upsg2000gro.googlegroups.com, RunThePun ubershme...@gmail.com wrote: On Sep 1, 3:00=A0am, a...@pythoncraft.com (Aahz) wrote: In article b11a8a0e-03ca-41c9-b0d0-c5180b6a2...@p15g2000vbl.googlegroups= .com, RunThePun =A0ubershme...@gmail.com wrote:

Re: Overriding iadd for dictionary like objects

2009-08-31 Thread RunThePun
On Aug 30, 10:33 pm, a...@pythoncraft.com (Aahz) wrote: In article e09276e8-8152-4002-8366-4c12705a8...@l35g2000vba.googlegroups.com, RunThePun  ubershme...@gmail.com wrote: I made a DictMixin where the keys are filenames and the values are the file contents. It was very simple and

Re: Overriding iadd for dictionary like objects

2009-08-30 Thread RunThePun
On Aug 29, 1:58 pm, Carl Banks pavlovevide...@gmail.com wrote: On Aug 28, 10:37 pm, Joshua Judson Rosen roz...@geekspace.com wrote: Carl Banks pavlovevide...@gmail.com writes: On Aug 28, 2:42 pm, Terry Reedy tjre...@udel.edu wrote: Carl Banks wrote: I don't think it needs a

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 Aahz
In article e09276e8-8152-4002-8366-4c12705a8...@l35g2000vba.googlegroups.com, RunThePun ubershme...@gmail.com 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-29 Thread Steven D'Aprano
On Sat, 29 Aug 2009 01:23:59 -0400, Joshua Judson Rosen wrote: Robert Kern robert.k...@gmail.com 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

Re: Overriding iadd for dictionary like objects

2009-08-29 Thread Carl Banks
On Aug 28, 10:37 pm, Joshua Judson Rosen roz...@geekspace.com wrote: Carl Banks pavlovevide...@gmail.com writes: On Aug 28, 2:42 pm, Terry Reedy tjre...@udel.edu 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

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Aahz
In article 21e57363-4e92-41cb-9907-5aef96ad0...@o15g2000yqm.googlegroups.com, RunThePun ubershme...@gmail.com 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

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Carl Banks
On Aug 26, 11:49 pm, RunThePun ubershme...@gmail.com 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

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 }

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

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Carl Banks
On Aug 28, 2:42 pm, Terry Reedy tjre...@udel.edu 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

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Joshua Judson Rosen
Robert Kern robert.k...@gmail.com 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

Re: Overriding iadd for dictionary like objects

2009-08-28 Thread Joshua Judson Rosen
Carl Banks pavlovevide...@gmail.com writes: On Aug 28, 2:42 pm, Terry Reedy tjre...@udel.edu 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.

Re: Overriding iadd for dictionary like objects

2009-08-27 Thread RunThePun
On Aug 27, 6:58 am, Robert Kern robert.k...@gmail.com wrote: On 2009-08-26 20:00 PM, Jan Kaliszewski wrote: 27-08-2009 o 00:48:33 Robert Kern robert.k...@gmail.com wrote: On 2009-08-26 17:16 PM, RunThePun wrote: I'd like to build a database wrapper using DictMixin and allow items to

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

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.

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:

Re: Overriding iadd for dictionary like objects

2009-08-26 Thread Jan Kaliszewski
27-08-2009 o 00:48:33 Robert Kern robert.k...@gmail.com 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()

Re: Overriding iadd for dictionary like objects

2009-08-26 Thread Jan Kaliszewski
27-08-2009 o 00:48:33 Robert Kern robert.k...@gmail.com 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()

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 robert.k...@gmail.com 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