Calling C from Python

Rich Somerfield rich_somerfield at
Tue Feb 20 12:01:11 CET 2001

Thanks for the info.

I attempted to complete the Calling Python from C [Demo/embed/demo.c] but
couldnt get it to compile.  Could u please help me with the command?
I was trying [on Unix] :
cc -o new

new.c -I/opt/Python-2.0/Include -I/opt/Python-2.0 -L/opt/Python-2.0 -L/opt/P
ython-2.0/Lib -L/opt/Python-2.0/Modules -lpython2.0

Where new.c is a copy of the demo.c file.


Dave Kuhlman <dkuhlman at> wrote in message
news:982605440.846771 at
> Section 1.1 of "Extending and Embedding the Python Interpreter"
> contains a simple but complete sample.
> You can also produce more complicated examples with SWIG, which
> will generate the wrapper functions for your C functions.  You can
> find SWIG at
> Also, in the source distribution, look at Demo/embed/demo.c.  It
> demonstrates both (1) embedding Python in a C application and (2)
> extending that embedded Python interpreter with a module
> implemented in C.  It's the second task that you seem to be asking
> for.
> Hope this helps.
>   - Dave
> Rich Somerfield <rich_somerfield at> wrote:
> >
> > Hi,
> > I have written a Game Engine in Python (main allow simulation of Board
> > using a config file as the definition of the game). The problem is, is
> > the AI section is too slow.  As the code needs to be generic (e.g. cant
> > specialise as the game type etc... is unknown until runtime - from
> > file), i have been unable to optimise the code further.
> >
> > I want to use Python as my main langauge and have certain code (where
> > performance is essential) written in C.  I have looked at the doc's and
> > get a feel for it.  Can anyone point me in the direction of some sample
> > (complete - not segments!), or give me a little helping hand?
> >
> > Cheers
> > Rich.
> >
> >
> --
> Dave Kuhlman
> dkuhlman at

More information about the Python-list mailing list