Calling C from Python

Dave Kuhlman dkuhlman at rexx.com
Mon Feb 19 12:57:18 EST 2001


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 http://www.swig.org.

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 tertio.com> wrote:
> 
> Hi,
> I have written a Game Engine in Python (main allow simulation of Board Games
> using a config file as the definition of the game). The problem is, is that
> 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 config
> 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 cant
> get a feel for it.  Can anyone point me in the direction of some sample code
> (complete - not segments!), or give me a little helping hand?
> 
> Cheers
> Rich.
> 
> 

-- 
Dave Kuhlman
dkuhlman at rexx.com



More information about the Python-list mailing list