Ctypes. ctypes run!
One of the new features of Python 2.5 is the introduction of ctypes as a core module. At the lowest level, ctypes adds the standard C types to Python: signed and unsigned bytes, shorts, ints and longs; as well as structs, unions, pointers and functions. At run-time it can load a shared library (DLL) and import its symbols, allowing a Python application to make function calls into the library without any special preparation. This capability can be applied to a variety of scenarios. Extension modules, traditionally written in C to wrap third-party libraries, can now be developed much faster in pure Python. Using ctypes has advantages over interface generators such as SWIG, such as a shorter development cycle and not requiring any static linkage. Application or library development in C is made easier by prototyping development in Python and incrementally replacing functions with high-performance counterparts, or by writing unit tests in Python for a C library. With a little trickery and care, ctypes can be used to manipulate memory and Python objects at the lowest level, providing immense speed improvements without needing to write or compile any native code. The presentation will walk the audience through the basic use of ctypes, show how it was used in the recent development of SDL-ctypes and Pygame-ctypes, and give a quick overview of its other applications and possibilities.
Keywords: Python, ctypes, Foreign Function Interface
Alex Holkner
No
|
Ref: OS6P0063