[omniORB] omniORBpy: string to omniORB.EnumItem instance

Duncan Grisby duncan at grisby.org
Mon Feb 12 10:21:15 GMT 2018


On Tue, 2018-01-30 at 16:30 -0500, chris williams via omniORB-list
wrote:

> Is it possible to convert a string to omniORB.EnumItem instance ?  I
> want to be able to accept a command line parameter and convert that
> to enum.
> 
> I have an enum defined as such in IDL:
> 
> enum IdlCommandType
> {
>    IDL_SETTINGS,
>    IDL_STATS
> 
> }
> 
> If I accept a command line parameter  "IDL_SETTINGS" (as a string),
> what is the python code to convert this to
> type _GlobalIDL.IDL_SETTINGS ?

That's just standard simple Python:

  param = # the parameter from the command line
  item  = getattr(_GlobalIDL, param)


If you want to check that the value really does belong to the right
enum, you can see if it is in the items:

  if item in _GlobalIDL.IdlCommandType._items:
      # It was a valid enum item


Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan at grisby.org     --
   -- http://www.grisby.org --




More information about the omniORB-list mailing list