while (a=b()) ...

Hrvoje Niksic hniksic at srce.hr
Sun May 16 18:42:53 EDT 1999


"Tim Peters" <tim_one at email.msn.com> writes:

> [Jim Meier]
> > ...
> > Aha! I see now... the * is intended to be the guarauneed-sequential
> > number of the current iteration, then?
> 
> "for x in thing:" follows a protocol that's *defined* to call
> thing.__getitem__ first with 0, then with 1, and so on.

...and at that, it's a very ugly protocol.  If memory serves me right,
you're supposed to signal end-of-sequence by explicitly raising
IndexError.  I wonder how expensive it is to trap and raise exceptions
in Python (I haven't looked at the interpreter code).  Maybe that's
why xrange() is slower than range() when common sense says it should
be the other way around.

> > I sympathise with the yearning, but my dislike is increased by the
> > (to me, anyways) non-intuitive feel of it.
> 
> The sequence 0, 1, 2, ..., or the asterisk?

I don't speak for Jim, but the asterisk is horribly unintuitive to me.
Almost reminiscent of that other language.




More information about the Python-list mailing list