<[EMAIL PROTECTED]> wrote:
> Simon Forman wrote:
> > But that's a function, not a class. When you assign add to an
> > attribute of Item it "magically" becomes a method of Item:
>
> Yes, I am looking to understand this magic.
> Sounds like I need to dig into these descriptor thingies (again).
>
Simon Forman wrote:
> But that's a function, not a class. When you assign add to an
> attribute of Item it "magically" becomes a method of Item:
>
Yes, I am looking to understand this magic.
Sounds like I need to dig into these descriptor thingies (again).
(sound of brain exploding)..
Simon.
[EMAIL PROTECTED] wrote:
> # This is what I have in mind:
>
> class Item(object):
> def __add__(self, other):
> return Add(self, other)
>
> class Add(Item):
> def __init__(self, a, b):
> self.a = a
> self.b = b
>
> a = Item()
> b = Item()
>
> c = a+b
>
> # Now, I am going abso
At Friday 25/8/2006 02:18, [EMAIL PROTECTED] wrote:
> x+y get translated to x.__add__(y)
No that's not true at all. The self argument to __add__ ends
up being the Add instance, not the Item instance:
z=x+y is translated to z.__add__(y)
Well, I deleted my response after I noticed that Simon
[EMAIL PROTECTED] wrote:
> Simon Forman wrote:
>
> >
> > "Item.__add__ = Add" is a very strange thing to do, I'm not surprised
> > it didn't work.
>
> Yes it is strange.
> I also tried this even stranger thing:
>
> class Item(object):
> class __add__(object):
> def __init__(self, a, b=None):
[EMAIL PROTECTED] wrote:
> Gabriel Genellina wrote:
> > At Friday 25/8/2006 00:36, [EMAIL PROTECTED] wrote:
> >
> > ># This is what I have in mind:
> > >
> > >class Item(object):
> > > def __add__(self, other):
> > > return Add(self, other)
> >
> > And this works fine... why make thinks compl
Simon Forman wrote:
>
> "Item.__add__ = Add" is a very strange thing to do, I'm not surprised
> it didn't work.
Yes it is strange.
I also tried this even stranger thing:
class Item(object):
class __add__(object):
def __init__(self, a, b=None):
print self, a, b
self.a = a
Gabriel Genellina wrote:
> At Friday 25/8/2006 00:36, [EMAIL PROTECTED] wrote:
>
> ># This is what I have in mind:
> >
> >class Item(object):
> > def __add__(self, other):
> > return Add(self, other)
>
> And this works fine... why make thinks complicated?
Yes, I agree it's simpler, and up u
[EMAIL PROTECTED] wrote:
> # This is what I have in mind:
>
> class Item(object):
> def __add__(self, other):
> return Add(self, other)
>
> class Add(Item):
> def __init__(self, a, b):
> self.a = a
> self.b = b
>
> a = Item()
> b = Item()
>
> c = a+b
>
> # Now, I am going absolutely
At Friday 25/8/2006 00:36, [EMAIL PROTECTED] wrote:
# This is what I have in mind:
class Item(object):
def __add__(self, other):
return Add(self, other)
And this works fine... why make thinks complicated?
# Now, I am going absolutely crazy with this idea
# and using it in a big way. S
# This is what I have in mind:
class Item(object):
def __add__(self, other):
return Add(self, other)
class Add(Item):
def __init__(self, a, b):
self.a = a
self.b = b
a = Item()
b = Item()
c = a+b
# Now, I am going absolutely crazy with this idea
# and using it in a big way. So
11 matches
Mail list logo