The need to put "self" in every method

Max M maxm at mxm.dk
Wed Jun 1 17:31:21 EDT 2005


Terry Hancock wrote:

> def __add__(a,b):
>     return Vector((a.x+b.x), (a.y+b.y), (a.z+b.z))
> 
> or something like that.  I still have twinges of guilt about it,
> though, and I had to write a long note in the comments, apologizing
> and rationalizing a lot. ;-)

Assigning self to a could have made it obvious:

def __add__(self, b):
     a = self
     return Vector((a.x+b.x), (a.y+b.y), (a.z+b.z))


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science



More information about the Python-list mailing list