Should a Python generator raise an exception when there are no more elements to yield?
Which one?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only time I know that you have to manually
raise StopIterationis when you are implementing anext()method on a class to signal that the iterator is terminated. For generators (functions withyieldstatements in them), the end of the function or areturnstatement will properly trigger theStopIterationfor you.