Detecting PyCObjects using type()
Lenny Hoffman
lenny.hoffman at objectivity.com
Mon May 21 15:53:26 EDT 2001
Hi Jeff,
I just had to solve the same problem. I have written an extension module,
but did not know how to export the "type" object for comparison to one
retrieved from the type function. What I ended up doing was to do a test
like this:
if str(type(arg1)) == "<type 'PyCObject'>":
One can easily imagine a helper function to perform this test given any type
name:
def isType(obj, typeName):
return str(type(obj)) == "<type '%s'>" % typeName
Perhaps a simular function exists, but I was unable to find one.
Regards,
Lenny
"Jeff Putsch" <putsch at fiber.mxim.com> wrote in message
news:mailman.990200847.25222.python-list at python.org...
> Howdy,
>
> I would like to be able to do something like this:
>
> class C:
> def __init__(self,arg1):
> if type(arg1) != type(PyCObject):
> raise AnException
>
> Unfortunately type(PyCObject) is not legal.
>
> If arg1 is a PyCObject, the type(arg1) returns:
>
> <type 'PyCObject'>
>
> What I can not figure out is what "type(PyCObject)" should be, to make the
> test work. With other types syntax like this works:
>
> if type(arg1) == type('')
>
> So my question boils down to this: what is the equivalent of "type('')"
when
> using PyCObjects?
>
> Thanks,
>
> Jeff.
>
>
>
More information about the Python-list
mailing list