title: Integrating C and Python: ValueError: module functions cannot set METH_CLASS or METH_STATIC
body: <p>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)</p>
  
  <p>npfind.h:</p>
  
  <pre><code>#include &lt;math.h&gt;
  
  extern int add(int a, int b);
  </code></pre>
  
  <p>npfind.c:</p>
  
  <pre><code>#include "npfind.h"
  
  int add(int a, int b)
  {
      return a + b;
  }
  </code></pre>
  
  <p>pynpfind.c:</p>
  
  <pre><code>#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", &amp;a, &amp;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);
  }
  </code></pre>
  
  <p>npfind.py:</p>
  
  <pre><code>from _npfind import *
  
  #Do stuff with the methods
  </code></pre>
  
  <p>npfindsetup.py</p>
  
  <pre><code>from distutils.core import setup, Extension
  
  setup(name="npfind", version="1.0", py_modules = ['npfind.py'],
        ext_modules=[Extension("_npfind", ["pynpfind.c", "npfind.c"])])
  </code></pre>
  
  <p>After all that, on Windows 7, I type</p>
  
  <pre><code>python npfindsetup.py build_ext --inplace --compiler=mingw32
  </code></pre>
  
  <p>Which seems to work. When I then try to find npfind.py, I get this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "npfind.py", line 1, in &lt;module&gt;
      from _npfind import *
  ValueError: module functions cannot set METH_CLASS or METH_STATIC
  </code></pre>
  
  <p>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?</p>