LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problem writing an extension for python! (https://www.linuxquestions.org/questions/programming-9/problem-writing-an-extension-for-python-401134/)

tuxfood 01-09-2006 05:06 AM

Problem writing an extension for python!
 
hi ..

I was reading the tutorial "Extending and Embedding the python interpreter" available with python ..

http://www.python.org/doc/2.2.3/ext/ext.html

As per given in the tutorial i created an interface to the system() system call.

this is the code of my module

Code:

#include<Python.h>

static PyObject * spam_system(self,args)
{
        PyObject * self;
        PyObject * args;
        char * command;
        int sts;

        if ( !PyArg_ParseTuple(args, "s" , &command))
                return NULL;
       
        sts = system(command);
        return Py_BuildValue("i",sts);
}

static PyMethodDef SpamMethods[] = {
        { "system", spam_system , METH_VARARGS,"Execute a shell command"},
        {NULL,NULL,0,NULL}
};

void initspam(void){
        (void) Py_InitModule("spam", SpamMethods);
}


int main(int argc,char **argv)
{
//        Py_SetProgName(argv[0]);

/* I COMMENTED THE ABOVE CALL AS IT GAVE ME SOME WIERD ERROR */
       
        Py_Initialize();

        initspam();
}

i was able to compile the above code using disutils package available with python .

http://www.python.org/doc/2.2.3/ext/building.html

I was even able to import the module into the python interpreter but caling the function gave me the following error

Code:

>>>import spam
>>>spam.system("ls -l")
python: Python/getargs.c:90: vgetargs1: Assertion `compat || (args != (PyObject*)((void *)0))' failed.
Aborted
[haynes@fosters:~/python]

whaaaaattttt????

any idea?

thnks

tuxfood


All times are GMT -5. The time now is 05:34 AM.