Checking the type of a PyObject

wim delvaux wim.delvaux at
Sun Aug 12 02:49:09 CEST 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

Example : calling from python

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

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

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



More information about the Python-list mailing list