generators not working? python 2.2
Cromwell, Jeremy
jcromwell at ciena.com
Fri Jan 11 13:29:57 EST 2002
The generator is not the function. You want to call the function that fib()
returns.
Try:
f = fib()
for i in xrange(1, 10):
print f.next()
> **********************************************************
> Jeremy Cromwell
> CIENA Core Switching Division
> jcromwell at ciena.com
>
-----Original Message-----
From: Mark McEahern [mailto:marklists at mceahern.com]
Sent: Friday, January 11, 2002 10:11 AM
To: python-list at python.org
Subject: generators not working? python 2.2
I tried this simple example from:
http://python.sourceforge.net/peps/pep-0255.html
and it doesn't seem to work? I'm probably doing something obviously wrong.
Please help.
$ python
Python 2.2 (#1, Dec 31 2001, 15:21:18)
[GCC 2.95.3-5 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import generators
>>> def fib():
... a, b = 0, 1
... while 1:
... yield b
... a, b = b, a + b
...
>>> for i in xrange(1, 10):
... print fib().next()
...
1
1
1
1
1
1
1
1
1
Thanks,
// mark
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list