overwrite set behavior

2008-09-04 Thread Michele Petrazzo
Hi all, I want to modify the method that set use for see if there is already an object inside its obj-list. Something like this: class foo: pass bar1 = foo() bar1.attr = 1 bar2 = foo() bar2.attr = 1 set( (bar1, bar2), key=lambda o: o.attr) and, of course, set has only one value. It's

Re: overwrite set behavior

2008-09-04 Thread Wojtek Walczak
On Thu, 04 Sep 2008 11:48:18 +0200, Michele Petrazzo wrote: Hi all, I want to modify the method that set use for see if there is already an object inside its obj-list. Something like this: ... It's possible? As far as I understand you, you need descriptors:

Re: overwrite set behavior

2008-09-04 Thread Marco Bizzarri
Ciao, Michele: On Thu, Sep 4, 2008 at 11:48 AM, Michele Petrazzo [EMAIL PROTECTED] wrote: Hi all, I want to modify the method that set use for see if there is already an object inside its obj-list. Something like this: class foo: pass bar1 = foo() bar1.attr = 1 bar2 = foo() bar2.attr =

Re: overwrite set behavior

2008-09-04 Thread Marco Bizzarri
On Thu, Sep 4, 2008 at 11:58 AM, Wojtek Walczak [EMAIL PROTECTED] wrote: On Thu, 04 Sep 2008 11:48:18 +0200, Michele Petrazzo wrote: Hi all, I want to modify the method that set use for see if there is already an object inside its obj-list. Something like this: ... It's possible? As far as

Re: overwrite set behavior

2008-09-04 Thread Diez B. Roggisch
Michele Petrazzo wrote: Hi all, I want to modify the method that set use for see if there is already an object inside its obj-list. Something like this: class foo: pass bar1 = foo() bar1.attr = 1 bar2 = foo() bar2.attr = 1 set( (bar1, bar2), key=lambda o: o.attr) and, of

Re: overwrite set behavior

2008-09-04 Thread Michele Petrazzo
Marco Bizzarri wrote: looking at the source, maybe you could create a subclass of Set redefining the __contains__ method? Made some tries, but __contains__ are never called class foo(set): ... def __contains__(self, value): ... print value ... a = foo((1,2)) Thanks, Michele --

Re: overwrite set behavior

2008-09-04 Thread Maric Michaud
Le Thursday 04 September 2008 14:31:23 Michele Petrazzo, vous avez écrit : Marco Bizzarri wrote: looking at the source, maybe you could create a subclass of Set redefining the __contains__ method? Made some tries, but __contains__ are never called No, __contains__ is only called with in

Re: overwrite set behavior

2008-09-04 Thread Marco Bizzarri
On Thu, Sep 4, 2008 at 3:07 PM, Maric Michaud [EMAIL PROTECTED] wrote: Le Thursday 04 September 2008 14:31:23 Michele Petrazzo, vous avez écrit : Marco Bizzarri wrote: looking at the source, maybe you could create a subclass of Set redefining the __contains__ method? Made some tries, but

Re: overwrite set behavior

2008-09-04 Thread Wojtek Walczak
On Thu, 4 Sep 2008 12:06:14 +0200, Marco Bizzarri wrote: As far as I understand you, you need descriptors: http://users.rcn.com/python/download/Descriptor.htm I know descriptors a litte, Wojtek, but didn't use them often; can you elaborate a little more on your idea? Marco, I think that I