I am making my first venture into integrating C and Python 2.7.3. For starters, I'm just trying to write a C module for Python that can do basic addition. (It is called npfind because once I figure this out, I want to write a find method for numpy)
npfind.h:
#include <math.h>
extern int add(int a, int b);
npfind.c:
#include "npfind.h"
int add(int a, int b)
{
return a + b;
}
pynpfind.c:
#include "Python.h"
#include "npfind.h"
static char* py_add_doc = "Adds two numbers.";
static PyObject* py_add(PyObject* self, PyObject* args)
{
int a, b, r;
if (!PyArg_ParseTuple(args, "ii", &a, &b))
{
return NULL;
}
r = a + b;
return Py_BuildValue("i", r);
}
static PyMethodDef* _npfindmethods = {
{"add", py_add, METH_VARARGS, py_add_doc},
{NULL, NULL, 0, NULL}
};
void init_npfind(void)
{
PyObject* mod;
mod = Py_InitModule("_npfind", _npfindmethods);
}
npfind.py:
from _npfind import *
#Do stuff with the methods
npfindsetup.py
from distutils.core import setup, Extension
setup(name="npfind", version="1.0", py_modules = ['npfind.py'],
ext_modules=[Extension("_npfind", ["pynpfind.c", "npfind.c"])])
After all that, on Windows 7, I type
python npfindsetup.py build_ext --inplace --compiler=mingw32
Which seems to work. When I then try to find npfind.py, I get this error:
Traceback (most recent call last):
File "npfind.py", line 1, in <module>
from _npfind import *
ValueError: module functions cannot set METH_CLASS or METH_STATIC
I cannot figure out what it is talking about. What are METH_CLASS and METH_STATIC, and why I am I trying to set them?