[IPython-user] Strange behaviour of generator in IPython
Fernando Perez
fperez at colorado.edu
Thu Aug 21 01:45:41 CDT 2003
Karl Pflästerer wrote:
> Hi,
> I searched the list archive and the bug tracker but found nothing about
> that issue (well I'm not sure if it's a bug so I report it first here).
>
> Python is 2.3 (Cygwin-version).
>
> If I write a simple generator like that:
>
> In [60]: def counter(start=1, step=1):
> ....: c = [start]
> ....: while 1:
> ....: yield c[0]
> ....: c[0] += step
> ....:
>
> In [61]: c = counter()
>
> In [62]: [c.next() for i in range(10)]
> Out[62]: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
>
> In [63]: [c.next() for i in range(10)]
> Out[63]: [31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
Hi Karl,
this was indeed a nasty problem which I think 0.5.0.rc1 fixed as of yesterday.
The root of the problem, a set of evals() hidden in the object finder, were
finally removed.
Please let me know if you see this problem again (which would very much
surprise me :)
Best,
f.
More information about the IPython-user
mailing list