[CentralOH] New Types
William McVey
wam at cisco.com
Thu Jun 14 21:01:10 CEST 2007
On Thu, 2007-06-14 at 08:07 -0400, David Car wrote:
> I'm just trying to learn to write extensions/new types in Python to
> interface
> with some other C code. So far so good, everything works. There's
> just that
> little nagging question I have about how it's setting a certain
> pointer in
> the PyObject structure for a new type.
Personally, I've never found myself needing to work at that level to
write an extension. If I really need to interface with a bit of C code,
I would generally write up a swig interface. Now days though, I am now a
big BIG fan of building hooks to C code using the ctypes module. I will
generally write a direct python mapping of a C library using ctypes,
then will use that one-to-one mapping of a C library accessible in
python via ctypes to build a python class that gives the C library a
pythonic structure and feel (objects, iterators, nice calling
conventions, etc)... It's been a winning strategy for me, and the fact
that I can avoid having to write C code again has been especially nice.
-- William
P.S. I've heard good things about pyrex as well for bridging C code to
python, although I've not personally used it.
More information about the CentralOH
mailing list