On Fri, Apr 29, 2005, Nick Coghlan wrote:
If you want to emphasise the similarity, the following syntax and explanation is something that occurred to me during lunch today:
We don't want to emphasize the similarity.
Python offers two variants on the basic iterative loop.
"for NAME from EXPR:" enforces finalisation of the iterator. At loop completion, a well-behaved iterator is always completely exhausted. This form supports block management operations, that ensure timely release of resources such as locks or file handles. If the values being iterated over are not required, then the statement may be simplified to "for EXPR:".
"for NAME in EXPR:" skips the finalisation step. At loop completion, a well-behaved iterator may still contain additional values. This form allows an iterator to be consumed in stages.
-1 -- the Zen of Python implies that we should be able to tell which construct we're using at the beginning of the line. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "It's 106 miles to Chicago. We have a full tank of gas, a half-pack of cigarettes, it's dark, and we're wearing sunglasses." "Hit it."