Question about exausted iterators

looping kadeko at gmail.com
Thu May 18 07:15:56 EDT 2006


Christophe wrote:
> Ok, call me stupid if you want but I know perfectly well the "solution"
> to that problem ! Come on, I was showing example code of an horrible
> gotcha on using iterators.
>

OK, your are stupid ;-)
Why asking questions when you don't want to listen answers ?


>
>
> Instead of saying that all works as intended could you be a little
> helpful and tell me why it was intended in such an obviously broken way
> instead ?

Why an exausted iterator must return an Exception (other than
StopIteration of course) ?
Well an exausted iterator could be seen like an empty string or an
empty list (or tons of others things), so you expect the code
for car in "":
  print car
to return an Exception because it's empty ???
It's your job to check the iterator when it need to be.

Regards.
Dom




More information about the Python-list mailing list