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
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:
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 =
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
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
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
--
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
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
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