[Tutor] Skipping elements from inside generator loops
Tim Peters
Tutor <tutor@python.org>
Sat, 03 Aug 2002 23:10:22 -0400
[Scot W. Stevenson]
> ...
> Now I'm curious: Is this ability to manipulate generator loops from the
> inside considered a bug or a feature?
It's a feature. Most people don't need .next() methods at all. By exposing
them, we're deliberately giving "advanced" users the opportunity to
"interfere" with Python's internal iteration protocol. You can use that for
good or for evil, but we hope you'll use it only for good. The same is true
of many internal hooks, and remember you're not *required* to use them!
Many hooks are there for the benefit of programs with extreme needs -- for
example, consider writing a Python debugger in Python. That's got to
"interfere" with normal Python operation is deep ways. Most programs don't
need any of that stuff. Comparatively speaking, .next() abuse is a minor
sin <wink>.