Problem with building extension in Python

cornpicker at gmail.com cornpicker at gmail.com
Wed Jul 18 09:42:59 EDT 2007


I solved my problem.

I had the math.h import step in the wrong location. The import step
needed to be outside of the function -- I'm so embarrassed.

Code: [Download]

   1.
   2. #
   3. #  Use C math functions
   4. #
   5.
   6. # Import the native C functions we need
   7. cdef extern from "math.h":
   8.     double cos(double theta)
   9.     double sin(double theta)
  10.
  11.
  12. def cTest(double theta):
  13.
  14.     cdef double result[2]
  15.
  16.     import sys
  17.
  18.     result[0] = cos(theta)
  19.     result[1] = sin(theta)
  20.
  21.     pyResult = (result[0], result[1])
  22.
  23.     return pyResult
  24.
25.



Now it works

If I type the following into the python shell

import cTest
cTest.cTest(.775)

The function returns

(0.71442103405593138, 0.69971607534660352)





More information about the Python-list mailing list