[Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

Raymond Hettinger python at rcn.com
Sat Dec 8 22:16:47 CET 2007


In your example, why do you "raise StopIteration" instead just writing "return"?

----- Original Message ----- 
From: "Manuel Alejandro Cerón Estrada" <ceronman at gmail.com>

Take a look at this example:

def lines():
    for line in my_file:
        if some_error():
            raise StopIteration()
        yield line
    yield 'end'

for line in lines():
    do_something()


More information about the Python-Dev mailing list