Friday, July 13, 2012

Wrapping Static Member Functions in Cython

I was trying to wrap a static member function with Cython, after some digging, I figured out how to do it...First, declare the function in the definition file ".pxd" in the class namespace:
#handle.pxd
cdef extern from "Handle.h" namespace "Handle":
    int getHandleCount()
Next, in the ".pyx" file use a class method to expose the function to Python code:
#handle.pyx 
cdef class Handle:
    @classmethod
    def get_handle_count(cls):
        return getHandleCount()

No comments:

Post a Comment