[IPython-user] embedding in C program

Amir amirnntp@gmail....
Sat Oct 18 02:55:35 CDT 2008


Hello.

I have embedded the Python interpreter in a C program. I would like to also
embed IPython to take advantage of it's many features.

1. I have the following basic program working, which starts up an IPython shell
from within a C program.

#include "Python.h"

main(int argc, char **argv)
{
  Py_Initialize();

  PySys_SetArgv(argc, argv);
  PyRun_SimpleString("from IPython.Shell import IPShellEmbed\n");
  PyRun_SimpleString("ipshell = IPShellEmbed()\n");
  PyRun_SimpleString("ipshell()\n");

  Py_Finalize();
}

2. Now, I would like to run commands through the IPython shell using the Python
C api with Py_CompileString and PyEval_EvalCode and read the result using
commands like PyArray_Check for a returned numpy array.

After instantiating an ipshell, is there a way to start it and pass commands to
it using the C api and read from the __main__ dict? Running ipshell() will just
start the interpreter and I wont be able to further call it from C.

Thanks,
Amir.




More information about the IPython-user mailing list