Chinaunix首页 | 论坛 | 博客
  • 博客访问: 212868
  • 博文数量: 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-22 11:05:20

#include "Python.h"

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

        Py_Initialize();
        PyRun_SimpleString("import sys");  
        PyRun_SimpleString("sys.path.append('.')"); 
        {
                PyObject *module = PyImport_ImportModule("example");
                PyObject *dictionary = PyModule_GetDict(module);
                PyObject *function = PyDict_GetItemString(dictionary"Add");

                PyObject *arguments = PyTuple_New(2);
                PyTuple_SetItem(arguments0PyInt_FromLong(1));
                PyTuple_SetItem(arguments1PyInt_FromLong(101));
                PyObject *result = PyObject_CallObject(functionarguments);
                rc = PyInt_AsLong(result);
        }
        Py_Finalize();
        printf("%d\n"rc);

        return 0;
}
       
文件:example.zip
大小:0KB
下载:下载
阅读(847) | 评论(0) | 转发(0) |
0

上一篇:在C中嵌入Python

下一篇:bt metainfo example

给主人留下些什么吧!~~