[Tutor] __mul__ for different variable types?

Warren warren at wantonhubris.com
Sun Oct 4 15:51:12 CEST 2009


I'm a little confused on this one.

I have a Vector class that I want to be able to multiply by either  
another vector or by a single float value.  How would I implement this  
in my override of __mul__ within that class?

Do you check the variable type with a stack of "if isinstance"  
statements or something?  What is the preferred Python way of doing  
this?

- Warren
(warren at wantonhubris.com)






More information about the Tutor mailing list