python语言是支持用c来它写模块的,其实现有的很多模块也是用c写的。这里我做个简单的介绍。
先决条件:
1.在linux上编写,需要自己编译出python的动态连接库。也就是要有libpython2.5.so这样的东西。
2.在windows上,则需要mingw这个编译环境。其实只要你安装了Dev-Cpp就有了。当然还安装了windows版的python.
一、先把源代码帖上来,很简单,假设保存为 hello.c
#include <Python.h> static PyObject * hello_echo(PyObject *self, PyObject *args, PyObject *keywds) { char *something; if (!PyArg_ParseTuple(args, "s", &something)) return NULL; printf(