Abstracting try..finally with generators (instead of macros)

Oren Tirosh oren-py-l at hishome.net
Mon Dec 16 04:47:16 EST 2002


On Mon, Dec 16, 2002 at 02:03:47AM +0200, Beni Cherniavsky wrote:
> Well, iterators that require finalization should be documented as such.
> After some reading I see that this is Python's general approach.  Implicit
> finalization can't be trusted.

But "no finalization" can...

> The for loop seems to be the only construct which holds an iterator
> without exposing it to user code so it must have this finalization
> support.  Besides, a for loop is the most common way to use iterators.

map(f,x), filter(f,x), dict(x), list(x) all iterate over x. 
i in x also iterates over x if it does not have a __contains__ method.

There are several other cases of implicit iteration.

	Oren




More information about the Python-list mailing list