I have a proto generated code which has 3 values (values i am interested in)
proto_type.VALUE1
proto_type.VALUE2
proto_type.VALUE3
I have created an enum in my python project.
class MyEnum(Enum):
VALUE1 = 0
VALUE2 = 1
VALUE3 = 2
The sole reason i have done this so that i can restrict callee to use specific values. Now I want to map MyEnum
to proto_type
values.
I was thinking to create a dictionary i.e.,
Mapping = {
MyEnum.Value1: imported_proto_type.VALUE1,
MyEnum.Value2: imported_proto_type.VALUE2,
MyEnum.Value3: imported_proto_type.VALUE3,
}
What i wanted to ask is this best pythonic way to do so? Is there any better approach?
source https://stackoverflow.com/questions/76058371/pythonic-way-to-map-enum-to-api-values
Comments
Post a Comment