How to stop iteration with __iter__() ?

Leo Jay python.leojay at gmail.com
Tue Aug 19 08:08:02 EDT 2008


On Tue, Aug 19, 2008 at 7:39 PM, ssecorp <circularfunc at gmail.com> wrote:
> I want a parse a file of the format:
> movieId
> customerid, grade, date
> customerid, grade, date
> customerid, grade, date
> etc.
>
> so I could do with open file as reviews and then for line in reviews.
>
> but first I want to take out the movie id so I use an iterator.
>
> then i want to iterate through all the rows, but how can I do:
> while movie_iter != None:
>
> because that doesn't work, itraises an exception, StopItreation, which
> according to the documentation it should. But catching an exception
> can't be the standard way to stop iterating right?
>

you can use for loop:
for line in movie_iter:
   ...



-- 
Best Regards,
Leo Jay



More information about the Python-list mailing list