[Python-Dev] expy: an expressway to extend Python

Yingjie Lan lanyjie at yahoo.com
Tue Jul 21 20:22:19 CEST 2009


Hi, 

Here is a brief example on how to use expy to implement the math module:
(for more details, see http://expy.sf.net/)


"""Python math module by expy-cxpy."""
from expy import * 
expymodule(__name__)

#includes, defines, etc.
@prologue 
def myprolog():
   return """
#include <math.h>
"""

@function(double) #return type: double
def sqrt(x=double): #argument x: double
   """sqrt(x) --> the square root of x."""
   return "sqrt(x)" #as an expression

#a more terse way
@function(double)
def sin(x=double):
   """sin(x) --> the sin of x."""
   pass #the deduced call: sin(x)

#more functions ...

expymodule(__name__) #end of module


      


More information about the Python-Dev mailing list