c/python integration

Shaun Hogan shogan at iel.ie
Fri Mar 10 18:26:32 CET 2000

right so, heres my problem,
i have this c code (below) and i want to call the functions getname() and
getnumber() from within the python interpreter, can anyone give me the code
i need or tell me how to do it pls

#define debug
/* #undef debug*/ // Uncomment this to compile with python
#ifndef debug
    #include "Python.h"
    #include <stdio.h>
    #include <stdlib.h>
#endif /*ndef debug */

typedef struct
    char name [100];
    int number;
}subscriber ;

int get_number (subscriber s);

char * get_name (subscriber s)
    char *t = (char *) malloc (sizeof (char) * 100);
    strcpy (t, s.name);
    return t;

#ifdef debug
int main (void)

#endif /*debug*/

int get_number (subscriber s)
    return s.number;

#ifndef debug
Py_Object * get_sub_details (Py_Object *, Py_Object *)
int get_sub_details(void)
#endif  /*debug */
    // this is one of the functions exported
    // to Python
    // For testing , create a sub object here
    subscriber test = {"Shaun", 100};
    printf ("name %s \t age %d\n", get_name (test) , get_number(test));

More information about the Python-list mailing list