[IPython-user] Embedding IPython in C program?

Herb Schilling hschilling at nasa.gov
Fri May 30 13:17:13 CDT 2003


Hi,

  I want to embed IPython in a C program. Here is the C code I am 
using to test this out.

#include <Python.h>

int main( int argc , char**argv )
{
   FILE       *fpInput ;

   if  ((fpInput = fopen ( argv[1], "r")) == NULL)
     {
       printf( "can't open file\n" ) ;
       return 1 ;
     }

   Py_Initialize(); /* Initialize the interpreter */
   PyRun_SimpleFile ( fpInput, argv[1] );

   return 0 ;
}



Here is the script I run from this C program:

from IPython.Shell import IPythonShellEmbed
ipshell = IPythonShellEmbed()
ipshell()


What I get as output is the help info ( plus a mysterious IE ) and 
nothing else.. See below for the first part of that output. Am I 
trying to do something that is impossible with IPython ? If it is 
possible, what am I doing wrong ?

Thanks!

IE

IPython -- An enhanced Interactive Python
=========================================

A Python shell with automatic history (input and output), dynamic object
introspection, easier configuration, command completion, access to the system
shell and more.

IPython can also be embedded in running programs. See EMBEDDING below.


USAGE
   ipython [options] files

If invoked with no options, it executes all the files listed in sequence and
drops you into the interpreter while still acknowledging any options you may
have set in your ipythonrc file. This behavior is different from standard
Python, which when called as python -i will only execute one file and will
ignore your configuration setup.

Please note that some of the configuration options are not available at the
command line, simply because they are not practical here. Look into your
ipythonrc configuration file for details on those. This file typically
installed in the $HOME/.ipython directory. For Windows users, $HOME resolves
to C:\Documents and Settings\YourUserName in most instances. In the rest of
this text, we will refer to this directory as IPYTHONDIR.


OPTIONS

All options can be abbreviated to their shortest non-ambiguous form and are
case-sensitive. One or two dashes can be used. Some options have an alternate
short form, indicated after a |.

Most options can also be set from your ipythonrc configuration file. See the
provided example for more details on what the options do. Options given at the
command line override the values set in the ipythonrc file.



-- 
Herb Schilling
NASA Glenn Research Center
Brook Park, OH 44135
Herbert.W.Schilling at nasa.gov

  "Punctuality is the virtue of the bored." (Evelyn Waugh)



More information about the IPython-user mailing list