[python-chinese] 用c扩展Python的一个小程序,但在命令行和IDLE下面结果不同,怀疑是IDLE的bug

ygao ygao2004在gmail.com
星期五 九月 1 22:35:54 HKT 2006


On 9/1/06, Wayne <moonbingbing在gmail.com> wrote:
>
> 程序如下:
>
> //mian.c
> #include<stdio.h>
> void rawprint(char *string)
> {
>     printf("%s\n",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啊
>
> --
> 温铭
> welcome to my blog : http://blog.csdn.net/wayne92
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>



-- 
※※※※※※※※※※※※※※※※※※※※※※※※
My blog:  http://blog.donews.com/ygao
Forum    http://groups.google.com/group/python_study
※※※※※※※※※※※※※※※※※※※※※※※※
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20060901/11b70401/attachment.htm 


关于邮件列表 python-chinese 的更多信息