Checking the type of a PyObject

Alex Martelli aleaxit at yahoo.com
Sun Aug 12 11:49:26 CEST 2001


"wim delvaux" <wim.delvaux at adaptiveplanet.com> wrote in message
news:3B75D4D4.61B32D80 at adaptiveplanet.com...
> Hi all,
>
> just looking at python and wondering if I could integrate it.
>
> While thinking I was wondering if one could determine the type of a
> PyObject
    ...
>           if( Py_GetType( FirstArg ) == String ) {

See http://www.python.org/doc/current/api/stringObjects.html

        if(PyString_Check(FirstArg)) {

performs exactly this.

>           } else if ( Py_GetType( FirstArg ) == Integer ) {

http://www.python.org/doc/current/api/intObjects.html

        if(PyInt_Check(FirstArg)) {


Another possibility is
http://www.python.org/doc/current/api/object.html

        PyObject theType = PyObject_Type(FirstArg);
        ...check with theType==PyString_Type , etc
        Py_DECREF(theType);    /* when done with it */


Alex






More information about the Python-list mailing list