LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-09-2006, 05:06 AM   #1
tuxfood
Member
 
Registered: Aug 2003
Location: kerala , India
Distribution: RH9 , FC1 ,
Posts: 141

Rep: Reputation: 15
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with mysql extension. Hum4ngus Linux - Newbie 2 08-12-2005 11:53 AM
Wireless Extension version problem? jeffk42 Linux - Wireless Networking 6 05-18-2005 12:50 PM
.tgz extension problem Jmcatch742 Linux - Newbie 1 10-24-2004 01:57 PM
Problem on adding an extension cord to mouse satimis Linux - Hardware 2 06-30-2004 09:26 AM
RedHat8->Apache2->PHP4->Extension (_Unwind_Resume) problem TimeSaver Programming 0 03-19-2003 01:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration