vc中调用python代码
来源:互联网 发布:数据分析ppt案例 编辑:程序博客网 时间:2024/06/11 07:48
运行一句python命令
对vc设置路径
include:D:/PYTHON31/INCLUDE
lib:D:/PYTHON31/LIBS
#include "stdafx.h"
#include "python.h"
int main(int argc, char* argv[])
{
Py_Initialize() ;
PyRun_SimpleString("print('Hello')");
//PyRun_SimpleString("print(dir())");
Py_Finalize();
return 0;
}
编译、连接
拷贝D:/Python31/python31.dll到exe文件目录
运行,输出到控制台
可以运行多行命令
Py_Initialize() ;
PyRun_SimpleString("x=100");
PyRun_SimpleString("print(x)");
PyRun_SimpleString("a=x*x/nprint(a)/n");
Py_Finalize();
相当于在python下运行下列代码
x=100
print(X)
a=x*x
print(a)
控制台输入
以下代码解释控制台输入
#include "stdafx.h"
#include "python.h"
int main(int argc, char* argv[])
{
Py_Initialize() ;
PyRun_AnyFile(stdin,NULL);
Py_Finalize();
return 0;
}
读取python变量值
将python运行结果读取到vc中
char *cstr;
PyObject *pstr;
PyObject *main_dict;
Py_Initialize() ;
PyObject* main_module = PyImport_AddModule("__main__");
main_dict = PyModule_GetDict(main_module);
PyRun_SimpleString("x='abc'");
pstr = PyRun_String("x", Py_eval_input, main_dict, main_dict);
PyArg_Parse(pstr,"s",&cstr); //转换
printf(cstr);
Py_Finalize();
- vc中调用python代码
- VC中调用JavaScript的代码片段
- VC中调用JavaScript的代码片段
- JNI调用VC++代码
- JNA调用VC++代码
- VC调用Python
- vc调用python
- 在Python代码中调用WPS
- C,C++代码中调用python脚本
- C,C++代码中调用python脚本
- 代码迁移攻略:在Java工程中调用Python代码
- VC++中调用word
- VC中调用exe
- VC中调用exe
- VC中调用Matlab
- VC中调用CLAPACK
- VC中调用exe
- VC中调用exe
- umdh使用
- C#.net 弹出没有最小化的窗口
- 不错的培训机构和课程
- PHP md5_file() 函数
- 记录让人感动的几个瞬间
- vc中调用python代码
- 从Google排名收购Admob案体会其收购之道
- 在CENT OS上编译安装APACHE+PHP+MYSQL
- 大规模数据处理
- 底层引擎类的架构写法
- C++ 类的基本概念
- Word如何取消自动拼写检查、自动句首字母大写
- 二叉树的java构造算法
- 龙族