[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Python and Speed



ctypes is great stuff! I find it much harder to crash the interpreter with ctypes than with extensions I've developed and debugged. It is quite resilient. I've used it to interface with the Windows API to simulate keystrokes, to interface to a USB Digital IO interface, in a wrapper for the huge OpenCV library, to set the background image on my desktop, to adjust the system volume control, to interface to the Wiimote, and to wrap eSpeak to name a few. I've pretty much given up on swig and pyrex.

gb

Greg Ewing wrote:
Ian Mallett wrote:
How do you write an extension module in C and call it from Python? Someone gave some instructions earlier, but I found them too vague...

Another way I forgot to mention earlier is to use the
ctypes module (I often forget about it, because it wasn't
in the stdlib until very recently.)

That allows you to call compiled routines from a shared
library directly without having to write any C. It's
less efficient, though, as it has to go through some
Python wrapper objects to get there, and also more
dangerous, because you can easily crash the interpreter
if you don't get everything exactly right.