Magnus Lie Hetland wrote:
> This is definitely a corner case -- and it may be an intentional
> incompatibility with Python (and, for all I know, I may have missed
> some documentation on it somewhere), but ... here goes:
>
> After a for-loop in Python, the index variable will retain its last
> value. E.g.:
>
>    for i in range(10): pass
>    print i
>    # Prints out 9
>
> In Cython, however, standard C-semantics are used for the counting for-
> loops, so the index variable is incremented one step beyond the value
> it had in the last iteration.
>
> I just wrote some code where this was an issue. It's easy to fix, of
> course (just use a statement like "i -= 1" or something) -- but it
> does mean an incompatibility between Python and Cython...

Definitely a bug, please file a bug report. (if you don't have a trac
account, please send a htpasswd line to Robert).


> I realise that adding an "i -= 1" statement in general, as a blanket
> solution, would be rather wasteful.

Not at all. We only do the range() optimisation for C integers, and the C
compiler will simply strip it out if it's not used.

Stefan

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to