[C++-sig] Check if object is of type Boost.Python.enum

matthew.scouten at gmail.com matthew.scouten at gmail.com
Tue Feb 19 02:05:17 CET 2013


There is no way to import, as Boost.Python.enum or Boost.Python.class. 
This can be a problem.

This is what I used when I was doing boost.python:

def isEnumType(o):return isinstance(o, type)and 
issubclass(o,int)andnot(o isint)

This also detects other subclasses of int, so if you are doing a lot of 
that, you will also want to check that the module is your extension 
module.

http://stackoverflow.com/a/3981011/8508

------ Original Message ------
From: "Davidson, Josh" <josh.davidson at lmco.com>
To: "cplusplus-sig at python.org" <cplusplus-sig at python.org>
Sent: 2/16/2013 4:21:23 PM
Subject: [C++-sig] Check if object is of type Boost.Python.enum
>I’m trying to find a clean way to test if an object in Python is of 
>type Boost.Python.enum:
>
> >>> myEnum.__bases__
>
>(<type 'Boost.Python.enum'>,)
>
>
>
>The easiest way would probably just be isinstance, but I can’t seem to 
>find a way to import Boost.Python.enum.  Anyone know how to import the 
>necessary module or have a better idea?  For what I’m doing, I can’t 
>simply rely on duck typing.
>
>
>
>Thanks,
>
>Josh
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20130219/10313840/attachment.html>


More information about the Cplusplus-sig mailing list