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

      今天写了一个用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啊
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值