Help creating extension for C function

Java and Swing codecraig at gmail.com
Fri Oct 7 15:47:58 EDT 2005


I need to write an extension for a C function so that I can call it
from python.

C code (myapp.c)
======
typedef unsigned long MY_LONG;

char *DoStuff(char *input, MY_LONG *x) { ... }

so you pass in a string and an array of MY_LONGS...such as

MY_LONGS vals[10] = {....};
char *input = "this is my input";
char *result;

result = DoStuff(input, vals);

...I need to create an extension so that I can call this from Python
such as...

>> import myapp
>> vals = [1,2,3,4,5,6,7,8,9,10]
>> input = "this is my input"
>> result = myapp.DoStuff(input, vals)
>> print result

ideally the result would be a String, vals would be a list and input
would be a string.

I was hoping to follow along with how to write an extension, as shown
here http://docs.python.org/ext/contents.html.

...but a better example would help.

Thanks.




More information about the Python-list mailing list