Checking the type of a PyObject

wim delvaux wim.delvaux at adaptiveplanet.com
Sat Aug 11 20:49:09 EDT 2001


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

Example : calling from python

Mod.Function( 1234 )
Mod.Function( "string" );

So Function should be callable with 2 different types (kind of
overloading)

in C  (Making abstraction of a lot of other stuff )

Mod_Function( PyObject *self, PyObject *args )  {

          PyObject * FirstArg;

           if (!PyArg_ParseTuple(args, "o", &FirstArg ))
               return NULL;

          /* And then something like */

          if( Py_GetType( FirstArg ) == String ) {
              char * String;
              PyArg_ParseTuple( args, "s", &String );
          } else if ( Py_GetType( FirstArg ) == Integer ) {
              long IVal;
              PyArg_ParseTuple( args, "i", &IVal);
          } else {
              return NULL;
          }
}

What would be the correct Python Library code to implement the above
pseudo code

Thanx

W





More information about the Python-list mailing list