C api question and determining PyObject type

lallous lallous at lgwm.org
Mon Nov 16 05:44:34 EST 2009


Actually, the object class is defined as:
    class __object(object):
        def __getitem__(self, idx):
            return getattr(self, idx)

Anyway, now I check like this:

bool PyIsSequenceType(PyObject *obj)
{
  if (!PySequence_Check(obj))
    return false;
  Py_ssize_t sz = PySequence_Size(obj);
  if (sz == -1 || PyErr_Occurred() != NULL)
  {
    PyErr_Clear();
    return false;
  }
  return true;
}

I don't like it, any other suggestions?

--
Elias
"lallous" <lallous at lgwm.org> wrote in message news:hdr80a$vsg$1 at aioe.org...
> Hello
>
> I have an a class defined as:
>
>    class __object(object):
>        pass
>
> Now, I call a C function that takes a PyObject* and checks its type:
>
> if (PyString_Check(obj)) ...
> if (PySequence_Check(obj)) ....
>
> Before doing the check, I print the passed object with PyObject_Str() and 
> get:
>
> passed object: <__main__.__object object at 0x040E4050>
>
> However, the C code returns true on the:
> if (PySequence_Check(obj)) ....
>
>
> Why? That is not a sequence?
> 




More information about the Python-list mailing list