Tobiah wrote:
[color=blue]
>
> def maker():
> for i in range(100):
> yield i
>
>
> foo:4: Warning: 'yield' will become a reserved keyword in the future
> File "foo", line 4
> yield i
> ^
> SyntaxError: invalid syntax
>
> Python 2.2.2
>
>
> ???[/color]
You seem to have omitted the necessary statement at the start
of your module (in Python 2.2):
from __future__ import generators
Alternatively, upgrade to 2.3, and you won't need that statement
any more.
|Tobiah wrote:
|> > def maker():
|> > for i in range(100):
|> > yield i
David Eppstein <eppstein@ics.u ci.edu> wrote previously:
|I guess this was just thrown together as an example of "yield", rather
|than real code, but:
|def maker():
| return range(100)
And less contorted still is:
xrange(100)
:-).
--
Keeping medicines from the bloodstreams of the sick; food from the bellies
of the hungry; books from the hands of the uneducated; technology from the
underdeveloped; and putting advocates of freedom in prisons. Intellectual
property is to the 21st century what the slave trade was to the 16th.
In article <yu994qynhi6q.f sf@tinker.resea rch.att.com>,
Andrew Koenig <ark@acm.org> wrote:
[color=blue]
> David> def maker():
> David> return range(100)
>
> David> seems a little less contorted...
>
> Maybe so, but it behaves differently so direct comparisons aren't
> particularly helpful:[/color]
I considered mentioning iter(range(100) ) instead but I couldn't think of
an actual reason one would care about the difference.
Comment