First question on extending Python...

Redefined Horizons redefined.horizons at gmail.com
Fri Jun 9 18:32:25 EDT 2006


I still new to Python, and I've only dabbled in C, but I've got my
first project I need to tackle that involves both languages. I was
hoping to get some advice on how to proceed.

There is a third-party application that I need to work with. It is
closed-source, but it exposes a C API. I want to wrap this C API so
that it is available from Python. I have no ability to modify the C
API of the third part application.

Do I the C functions that I wrap in an extensions module for Python
need to be in a certian format? If so, I will have to write an
intermediate DLL in C that wraps the third-party application and
exports the functions in a form that Python can use.

Or can an extension module for Python wrap any C function? If this is
the case I think I can skip the intermediate C DLL.

Are there any advantages to using the intermediate DLL written in C in
this particular case where I will not have ability to manipulate the C
API of the third party application directly? (For example, if the
third-party application developers are willing to call a "call-back"
function that must be written in C, but not Python. Could the same
extension module export both C functions and serve as a Python
module?)

Thanks,

Scott Huey



More information about the Python-list mailing list