RangeFromConverting
robertwb edited this page Jul 3, 2011
·
9 revisions
Update: this can now be handled automatically (and more selectively) via an option. See http://wiki.cython.org/DifferencesFromPyrex
Imagine this simple file:
The generated code is slow though, because range() is slow. I can either manually change all ranges to the "from 1 <= i <= dim -1" idiom, but that's annoying. I prefer Cython to do it automatically (for example by providing a switch "--convertrange" or something, it doesn't have to be default).
Here is a simple script which does that:
attachment:convertRange.py
It opens a file, changes all range(..) to from ..., and prints the result to stdout. You need pyparsing to run it:
$ python convertRange.py exampleIn.pyx
produces:
attachment:exampleOut.pyx