[capi-sig] Checking int type

Jon Parise jon at indelible.org
Mon May 24 08:56:21 CEST 2010


On Sun, May 23, 2010 at 7:40 AM, Vojtěch Rylko <vojta.rylko at seznam.cz> wrote:

> what am I doing wrong?
>
> C code:
> --------------
> static PyObject *is_prime(PyObject *self, PyObject *value)
> {
>    if (!PyInt_Check(value)) {
>        PyErr_SetString(PyExc_TypeError, "only integers are acceptable");
>        return NULL;
>    }
> --------------
>
> Test (I'm using integer 3):
> ------------
>>>> primes.is_prime(3)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> ValueError: only integers are acceptable
> -------------

The second argument ('value', in your code) is actually a tuple
containing the arguments passed to your is_prime() function.  You'll
need to unpack the individual values from that tuple.

http://docs.python.org/extending/extending.html#extracting-parameters-in-extension-functions

-- 
Jon Parise (jon of indelible.org)  ::  "Scientia potentia est"


More information about the capi-sig mailing list