What's wrong?

kishkin kishkin at gmail.com
Wed Jan 25 03:42:16 EST 2006


Hello everyone!

I wanted to write python script with defined function. From that script
I wanted to call C module, which in it's turn call defined python
function. Sounds simple. But I've got some troubles in realization. I'm
beginner at python so it's normal, I think. :)

Here's the code. I'll apreciate if anyone can answer me what's wrong
here.

-------------------------------------------------------------------
power.c:

#include "Python.h"

static PyObject *
power(PyObject *self, PyObject *args)
{
  PyObject *result, *temp;

  int num;

  if (PyArg_ParseTuple(args, "iO", &num, &temp))
  {
    if (!PyCallable_Chack(temp))  //here's error, but I don't know
why...
    {
      return NULL;
    }
  }

  result = Py_BuildValue("i", num*num);

  PyEval_CallObject(temp, result);
  Py_DECREF(result);

  Py_INCREF(Py_None);
  retrun Py_None;
}

static struct PyMethodDef power_methods[] = {
   {"power", power, METH_VARARGS, "powering number"},
   {NULL, NULL, 0, NULL}
};

void initpower()
{
   (void) Py_InitModule("power", power_methods);
}
-------------------------------------------------------------------

-------------------------------------------------------------------
power.py:

import power

def sst(some):
    print some

power.power(9, sst)
-------------------------------------------------------------------




More information about the Python-list mailing list