pyrex.internal_functions.get_from_enum¶
-
pyrex.internal_functions.
get_from_enum
(value, enum)¶ Find the enum value given some representation of it.
Transforms the given value into the corresponding value from the
enum
by checking the type of value given.- Parameters
- value
Representation of the desired
enum
value. If already a member ofenum
, no change. Ifstr
, assumed to be a name in theenum
. Otherwise, assumed to be a value type of theenum
.- enumEnum
Python
Enum
to compare names values with.
- Returns
- Enum value
Value in the
enum
represented by the given value.
Examples
>>> from enum import Enum >>> class Color(Enum): ... red = 1 ... green = 2 ... blue = 3 >>> get_from_enum(Color.red, Color) <Color.red: 1> >>> get_from_enum("green", Color) <Color.green: 2> >>> get_from_enum(3, Color) <Color.blue: 3>