Wrapper classes: creating a python wrapper for a C project

I am new to python programming but programmed in C. I am working on the EtherDogs project which is a network packet analyzer. How do I start writing a python wrapper for a project?

It wouldn't be difficult if I had to use a C ++ wrapper for it, but how do I do it in python?

+3


source to share


1 answer


You should try a wrapper generator like SWIG . Writing glue code by hand is repetitive and boring. Why don't you make the computer the easy parts for you?

SWIG will take the source files and the (minimal) interface specification. It will create Python proxy classes and C / C ++ code. You compile your C / C ++ code into a Python Extension Library and then use it just like you would in a pure-Python library. Under the hood, SWIG proxy classes generate a descriptor that converts Python types to / from calls to original C functions.



As an added bonus, wrapper generators (including SWIG) can usually create bindings for different high-level languages ​​with little or no extra effort on your part.

+4


source







All Articles