Friday, November 18, 2005

Instant C/C++ in Python

Instant is a module if found using PyPi that has a nice option for python developers, and C(++) developers alike. Just take al ook at this:
>>> c_code = """
double sum(double a, double b){
return a+b;
>>> import Instant
>>> ext = Instant.Instant()
>>> # create the wrapper code, compile and link it to a shared library
>>> ext.create_extension(code=c_code, module='test1_ext')
>>> from test1_ext import sum
>>> # use the C code
>>> print sum(3.7, 4.8)

It creates C source code as a Python String, only to compile it in 3 lines! Compile something else, 1 more line!!

Import the newly created compiled module, takes 1 extra line, but i guess everyone can live with that.