Which style is preferable?
Antoon Pardon
apardon at forel.vub.ac.be
Mon Jul 19 05:01:27 EDT 2004
Op 2004-07-16, Lonnie Princehouse schreef <finite.automaton at gmail.com>:
> Why do type checking at all?
>
> Element-wise addition will raise an exception if you're trying to add
> two elements that can't be added. If you insist on type checking, then
> mechanisms like implicit conversion (i.e. int->float) and overloaded
> operators won't have a chance to work their magic.
>
> PS- Try making Vector a subclass of list:
>
> class Vector(list):
> def __add__(self, other):
> return Vector([ a + b for a, b in zip(self, other)])
I don't thing making Vector a subclass of list is a good
idea. The '+' operator is totally different for lists
and vectors. If python would use a different symbol
for concatenation, I probably would try it like this,
but now I feel it will create too much confusion.
--
Antoon Pardon
More information about the Python-list
mailing list