samedi 31 décembre 2016

How to insert a python code in C++?

i am trying to embed a code python in c++. I have this python code :

#include <Python.h>

int main(int arg){
Py_SetProgramName(argv[0]);
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"

                     "print 'Today is',ctime(time())\0");
Py_Finalize();
return 0;
}

but what i want is something like that :

include

int main(int arg){
Py_SetProgramName(argv[0]);
int a = 5;
Py_Initialize();
PyRun_SimpleString("a = "+a);
Py_Finalize();
return 0;
}

but it does not work. I mean i want with python to display the value of the variable a. Thank you :)

Aucun commentaire:

Enregistrer un commentaire