Saturday, August 13, 2011

Cython - notes and gotchas - part 1

Experimenting with Cython, as bringing together many variants of the same .c file, has me yearning to find a better Python / C balance.

Working through tutorials and experiments, I will note anything tricky, or any easy to fall into traps.

TypeError: 'NoneType' object is not callable:

Because Python is flexible, and does not insist on you declaring variables ahead of time, you may be tempted to do the same in Cython.

Better to declare the variable 'primes' explicitly, or to avoid name clashes.

So in the second example the result of the function call ends up in 'primes_list_strings' and we work on it from there.

To clarify the original error: Calling the variable that holds the result 'primes', and making a function call to primes() in the same line, might lead to confusion.

Notes and Further Reading:

If you want completion features when working with Python, then one solution is to invoke iPython and use that.

There are several full IDEs for Python including Idle and Eric, but if you just need a little completion (and syntax highlighting), then iPython is okay also.

Screenshot of Eric from

No comments:

Post a Comment