from __future__ import generators
Jeff Shannon
jeff at ccvcorp.com
Fri Aug 10 16:51:50 EDT 2001
gzeljko wrote:
>
> Is 1 'yield' worth 100000 'from __future__ import generators' ? :)
>
Well, you only need 'from __future__ ...' in modules that actually use
generators, so the ratio is a lot closer to 1:1.
Hm... I don't have 2.2a installed or I'd just try this, but... if I've
got a module that declares a generator:
--------- gen1.py ----------
from __future__ import generators
def g():
for i in xrange(100):
yield i
----------------------------
And then a second module that imports gen1 and uses that generator....
-------- gen2.py -----------
import gen1
for n in gen1.g():
foo(n)
------------------------
Would gen2.py also require the __future__ statement? Or, is gen1.g()
returning a "plain" iterator, thus rendering the __future__ irrelevant
in gen2.py ??
(Gotta install 2.2a sometime soon.... )
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list