您的位置:首页 > 编程语言 > Python开发

菜鸟学Python(5):IDLE的一个bug(怎么总遇到bug?)

2007-09-21 17:47 731 查看
今天写了一个用c扩展Python的小程序,在IDLE下总也得不到结果,后来在老大(不会Python)的指导下,怀疑是IDLE的一个bug。记一下,以后有人遇到也好知道不是自己程序的问题,不用像我一样再花几个小时的时间了。

程序如下:

main.c


#include<stdio.h>


void rawprint(char *string)


{


printf("%s ",string);


}

wrap.c



#include<python.h>


extern void rawprint(char*);




PyObject *testex_rawprint(PyObject *self,PyObject *args)


{


char *string;


if( !PyArg_ParseTuple(args,"s",&string) ){


return NULL;


}


rawprint(string);


Py_INCREF(Py_None);


return Py_None;


}




static PyMethodDef testexmethods[] = {


{"rawprint", testex_rawprint,METH_VARARGS,
"print a raw string"},


{NULL,NULL},


};




void inittestex(void)


{


Py_InitModule("testex",testexmethods);


}

然后用命令
gcc -shared -I"c:/Python24/include" -L"c:/Python24/libs" *c -lpython24 -o t
estex.dll
生成动态链接库并复制到c:/Python24目录下。

在IDLE下:


>>> import testex


>>> testex.rawprint('hello')


>>>

没有打出hello

在命令行下就可以打出hello

原以为是程序的问题,改了多次还是不行。开始怀疑是IDLE的bug,换用Wing IDE,可以打出hello。

faint,令人郁闷的IDLE啊
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: