views:

303

answers:

4

I have a legacy C library that creates a tree of objects. I would like to convert the tree into a pre-existing Python class. How do I create the PyObject for that class?

+1  A: 

Take a look at generating your Python bindings by using a tool such as pybindgen. These guys are trying to make a superior binding generator, they talk about the shortcomings of other tools (e.g. SWIG) on their front page.

joshperry
+1  A: 

I've had success using Robin in these scenarios.

orip
A: 

If you're looking to create a python module, which can access your c code, you want to read up on Extending and Embedding the python interpreter.

JimB
+3  A: 

Cython is capable of doing this. It's a semi-fork of Pyrex, and it can wrap existing data structures and expose them to Python. In fact, this is one of the sections in the user guide. Cython is relatively easy to use, and it includes an HTML-output format that shows all the generated code as well as highlighted hot spots where optimization could be applied.

Matt
I agree. I've had good success with Cython.
Brian Clapper