Which style is preferable?
Terry Reedy
tjreedy at udel.edu
Fri Jul 16 16:48:34 EDT 2004
"Pete Shinners" <pete at shinners.org> wrote in message
news:cd8qpd$gr1$1 at sea.gmane.org...
> Antoon Pardon wrote:
> > For the sake of this question I'm writing a vector class. So
> > I have code something like the following
>
> I find all the type checking a touch ugly, but perhaps I've been using
> Python for too long. I would approach it like this.
I have 3 minor comments on the original code:
> self.val = [ el for el in iter ]
list(iter) is clearer and, I believe, faster
> raise TypeError
I recomment the addition of an informative error message to all raises.
> if len(self.val) != term.val:
You left something out here...
However, Pete's replacement code is, in my opinion too, much better, even
with these edits.
Terry J. Reedy
More information about the Python-list
mailing list