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
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@lmco.com> To: "cplusplus-sig@python.org" <cplusplus-sig@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
participants (2)
-
Davidson, Josh -
matthew.scouten@gmail.com