I am looking for an enum-based approach to return an array behind each enum item. For example, suppose that I need to specify a range for each type of target such as the following:
from enum import Enum
class TargetRange(Enum):
T1 = [0, 100]
T2 = [30, 60]
T3 = [50, 150]
Now, I am using the enum like the following:
target_range = TargetRange.T1
value = 140
# ...
# adjust the value
if(value > target_range[1]):
value = target_range[1]
elif(value < target_range[0]):
value = target_range[0]
# ...
But, I get the following error:
TypeError: 'TargetRange' object is not subscriptable
How can I resolve it? What is the correct usage of this kind of enum?
I should note that I found this post to return a string (instead of an array). Hence, I am looking for the same idea for returning array instead of a string.