Hello everybody, Sorry to reply to myself, just wanted to mention that I found a real need for iterators to have an explicit "finally" action. For my program I will have to invent some convoluted way of doing it :-( On Mon, Feb 03, 2003 at 05:10:42PM +0100, Armin Rigo wrote: > If no first-class thunks are wanted, then maybe the most direct path from > today to auto-closing files is to extend the iterator protocol with an > optional __leave__() method. It would be called exactly once when the > iterator is considered to be exhausted. The semantics of 'for' would be > modified to always call it at the end of the loop, even when an exception or a > return occurs within the loop. This seems (to me) natural because in generators you could then put a 'yield' inside of a 'try-finally' pair. The semantics of def g(): try: yield 5 finally: <so-some-cleanup> are quite clear if it is guaranteed that for x in g(): ... always cause the 'finally' part of the generator to be called at the end of the loop. That's even something that is straightforward to implement, given that loops already set up a block stack entry, just like try-finally clauses. It just adds an extra function to the iterator protocol (we could even reasonably re-use tp_clear, for example). Armin
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4