菜鸟学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啊
程序如下:
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啊
相关文章推荐
- 菜鸟学Python(5):IDLE的一个bug(怎么总遇到bug?)
- python3中遇到的一个bug TypeError: is_empty() takes 0 positional arguments but 1 was given
- python orm框架sqlalchemy执行更新、删除时遇到的一个bug
- python orm框架sqlalchemy执行更新、删除时遇到的一个bug
- Python搭建API,并通过Thrift 和C++进程通信,遇到了一个大BUG!
- 又遇到Python另外一个问题:函数作参数,怎么传递参数?
- 他妈的 Python(1):怎么发起一个同步的 HTTP 请求
- 遇到bug怎么办
- vue计算属性时v-for处理数组时遇到的一个bug问题
- 遇到一个Bug:Android: requestLayout() improperly called
- onethink动态扩展菜单中遇到的一个小bug解决思路
- python win32com 遇到的一个奇怪的错误
- 找回Python IDLE Shell里的历史命令(用上下键翻历史命令怎么不好用了呢?)
- 菜鸟遇到的一个问题的解决方案
- 菜鸟学Python(6):在Linux下用C扩展Python要注意的一个问题
- 今天遇到了一个问题,怎么判断你输入的数是整数 ----2012.6.28
- LVS负载均衡软件在处理Netfilter/iptables连接状态跟踪机制时遇到的一个bug的说明
- 最近遇到一个问题,怎么修改环境网站访问总会报ASP.NET 4.0错
- CorelDraw油字体怎么做是一个菜鸟和大师的区别
- android app检查更新遇到的一个小bug