I'm creating an application in Python with dynamic scripting that allows users to create their own Python scripts and manipulate the application. I would much rather make the application in c++ but I also want the custom Python script manipulation. So... basically I need c++ to read and execute Python scripts. Is there a way to do this?
Asked
Active
Viewed 155 times
1
-
possible duplicate of [Integrate Python And C++](http://stackoverflow.com/questions/1153577/integrate-python-and-c) – Sully Mar 19 '14 at 06:04
-
I looked at that. Didn't really help me. – David Ludwig Mar 19 '14 at 06:50
1 Answers
0
Yes, you'll want to look at Embedding Python in Another Application. Here's the example from "Very High Level Embedding" from the python docs.
#include <Python.h>
int
main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
return 0;
}

Aaron
- 2,341
- 21
- 27