Paul Moore wrote: > On 5/8/05, Jp Calderone <[EMAIL PROTECTED]> wrote: > >> If such a construct is to be introduced, the ideal spelling would seem to >> be: >> >> for [VAR in] EXPR: >> BLOCK1 >> finally: >> BLOCK2 > > > While I have not been following this discussion at all (I don't have > the energy or time to follow the development of yet another proposal - > I'll wait for the PEP) this does read more naturally to me than any of > the other contortions I've seen passing by.
Given this for loop syntax: for VAR in EXPR: BLOCK1 else: BLOCK2 finally: BLOCK3 And these semantics when a finally block is present: itr = iter(EXPR1) exhausted = False try: while True: try: VAR1 = itr.next() except StopIteration: exhausted = True break BLOCK1 if exhausted: BLOCK2 finally: try: BLOCK3 finally: itr_exit = getattr(itr, "__exit__", None) if itr_exit is not None: try: itr.__exit__(TerminateBlock) except TerminateBlock: pass "Loop on this iterator and finalise when done" would be written: for item in itr: process(item) finally: pass If you just want the finally clause, without finalising the iterator, you write it as you would now: try: for item in itr: process(item) finally: finalisation() I like it - I'll update the PEP redraft to use it instead of the 'del' idea. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.blogspot.com _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com