Detecting PyCObjects using type()

Fredrik Lundh fredrik at pythonware.com
Fri May 18 12:56:05 EDT 2001


Jeff Putsch wrote:
>
> 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?

get hold of something you know is a PyCObject, and extract
its type on the module level.  here's one way to do it:

    import cStringIO
    CObjectType = type(cStringIO.cStringIO_CAPI)

    ...

    def __init__(self,arg1):
         if not isinstance(arg1, CObjectType):
            raise AnException

    ...

Cheers /F





More information about the Python-list mailing list