How does python invoke external C function?
Wolfgang Grafen
Wolfgang.Grafen at marconicomms.com
Fri Jun 16 03:15:39 EDT 2000
Sam Wun wrote:
> Hi,
>
> I would like Python call an external C function ( ie. char
> *getString()),
> Does anyone knows how to do that?
>
> Thanks
> Sam.
I would recommend SWIG for a first step. You don't have to learn a lot
about extension
modules with SWIG. Often it is easy like this (for sun solaris 2.5):
swig -python -module a a.c
gcc -O02 -DSWIG -c -fpic a.c a_wrap.c \
-I/user/freepool/sparc-sun-solaris2.5.1/lib/python/python1.52/include/python1.5/
ld -G a.o a_wrap.o -o a.so
Then in Python you can use it like it is.
Python 1.5.2 (#33, May 17 2000, 17:03:52) [GCC 2.7.2] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import a
>>> dir(a)
['__doc__', '__file__', '__name__', 'hex2bin', 'hex2bin_char',
'hex2bin_expand']
>>>
SWIG has a very good documentation. You can build extensions for PERL
and TCL
the same way
http://www.swig.org
There is also another Corba-like Package called ILU. Probably SWIG is
more easy to use while
ILU might be more powerful.
ftp://ftp.parc.xerox.com/pub/ilu/ilu.html
Regards
Wolfgang
More information about the Python-list
mailing list