overloading __mul__

Raymond Hettinger vze4rx4y at verizon.net
Wed Mar 12 23:54:06 EST 2003


> I'm defining 2 clases. They are like a matrix anda a vector.  The
> matrix
> is a square one using list insie list [[1,2],[3,4]] and the vector is
> a list [5,6].
>
> I want to be able to write things like that
>   2*matrix
>   matrix * 2
>   2*vector
>   vector *2
> but also
>   matrix*vector
>   vector*matrix

For an example, see my matrix module at:

   http://users.rcn.com/python/download/python.htm


Raymond Hettinger






More information about the Python-list mailing list