Using '__mul__' within a class



Hello

I'm pretty new to Python and was wondering why the 'Square' method in
the following code doesn't work. It doesn't fail, just doesn't do
anything ( at least, not what I'd like! ). Why doesn't 'A.a' equal 2
after squaring?
TIA.


class FibonacciMatrix:
def __init__( self ):
self.a = 1
self.b = 1
self.c = 0

def __mul__( self, other ):
result = FibonacciMatrix()
result.a = self.a * other.a + self.b * other.b
result.b = self.a * other.b + self.b * other.c
result.c = self.b * other.b + self.c * other.c
return result

def Square( self ):
self *= self


A = FibonacciMatrix()
A.Square()

print A.a #prints '1'

A = FibonacciMatrix()
B = A * A

print B.a #prints '2'

------------------------------

.



Relevant Pages

  • Re: Conibear style surfaces
    ... Now, guys, just for clarification, does this means squaring in the ... squaring (or feathering) the blade should be done the same as the rest ... sequence was extract, feather, hands away, square, body through, slide. ...
    (rec.sport.rowing)
  • Re: Question regarding c^2
    ... What is the significance of squaring the speed of light? ... so much in areas such as relativity, but what does the act of ... The resulting units will be the square of the ... human inventions and two humans can choose ...
    (sci.math)
  • Re: Using __mul__ within a class
    ... def Multiply: ... but it works a little differently than Square() ... > class FibonacciMatrix: ... James Stroud ...
    (comp.lang.python)
  • Re: Old Tea Leaf Reviews 6: 1986 Locus Poll Best First Novel
    ... ie, not a unitless number. ... Squaring a speed doesn't get you a speed. ... anything when you say "the speed is the square of the speed oflight". ... square of the speed of light in farquads per bleen", ...
    (rec.arts.sf.written)
  • Re: Mews Square Mode ...
    ... > Square mod ~ ... > Don't see how would Montgomery help ... > Here ~ It's just squaring, ... > Not exponentiation with a big exp. ...
    (sci.crypt)