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
enumby checking the type of value given.- Parameters
- value
Representation of the desired
enumvalue. 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
Enumto compare names values with.
- Returns
- Enum value
Value in the
enumrepresented 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>
