Chinaunix首页 | 论坛 | 博客
  • 博客访问: 212866
  • 博文数量: 70
  • 博客积分: 2050
  • 博客等级: 大尉
  • 技术积分: 700
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-15 21:42
文章分类

全部博文(70)

文章存档

2013年(1)

2011年(5)

2010年(3)

2009年(9)

2008年(17)

2007年(6)

2006年(29)

我的朋友

分类: C/C++

2008-01-21 18:38:29

#include "Python.h"

static int counts;

PyObject *incr(PyObject *selfPyObject *params)
{
        int request;

        if(!PyArg_ParseTuple(params"i", &request))
        {
                fprintf(stderr"bad request.\n");
                return 0;
        }

        return PyInt_FromLong(counts += request);
}

PyMethodDef exports[] =
{
        {"incr"incrMETH_VARARGSNULL},
        {NULLNULLNULLNULL}    
};

int main(int argcchar *argv[])
{
        int i;

        Py_Initialize();
        if (!Py_InitModule("examples"exports))
        {
                fprintf(stderr"`examples' can't be initialized.\n");
                return 1;
        }
        for (i = 1i < argc; ++i)
        {
                FILE *fp = fopen(argv[i], "r");
                if (fp)
                        PyRun_AnyFileEx(fp01);
        }
        Py_Finalize();

        return 0;
}

文件:example.zip
大小:0KB
下载:下载
               
阅读(907) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~