1

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?

David Ludwig
  • 967
  • 2
  • 12
  • 26

1 Answers1

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