python/C API接口

发布时间:2019-06-28 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了python/C API接口脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

include <python2.7/Python.h>

bool ParseEmail(char FilePath,char *sender){
PyObject * g_pModule = NULL;
PyObject
parg = NULL;
PyObject* PRetVal = NULL;
int iRetVal = 0;
Py_InITialize();
if (!Py_IsInitialized())
{
printf("Error:Init Mode Errorn");
return FALSE;
}
PyRun_SimpleString("import Sys");
PyRun_SimpleString("sys.path.apPEnd('./ParseEmail')");
//这里是要调用的文件名,我们这里是当前目录下
//导入模块
g_pModule =PyImport_ImportModule("ParSEMail");
if (!g_pModule) {
printf("Error:Import Mode Failed!n");
return FALSE;
}
//查找函数
PyObject * Email = PyObject_GetAttrString(g_pModule,"ParseSent");
if((Email) == NULL){
printf("Error:Retrieve an attribute named Failedn");
}
//这里是要调用的函数名
//参数
pArg=PyTuple_New(2);
PyTuple_SetItem(pArg,0,Py_BuildValue("s",FilePath));
PyTuple_SetItem(pArg,1,Py_BuildValue("s",sender));
PyObject *objResult = PyObject_CallObject(Email,pArg);
//调用函数
if (!objResult){
printf("Error:Invoke Function Failn");
return FALSE;
}
Py_Finalize();//调用Py_Finalize,这个跟Py_Initialize相对应的.
return TRUE;
}

脚本宝典总结

以上是脚本宝典为你收集整理的python/C API接口全部内容,希望文章能够帮你解决python/C API接口所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。