假设有两个从
什么是遍历嵌套Enum的最佳方法(可能是递归),例如上面示例中的
Enum
派生的类,例如:class Color(Enum):
blue = 'blue'
red = 'red'
class Properties(Enum):
height = 'h'
weight = 'w'
colors = Color
什么是遍历嵌套Enum的最佳方法(可能是递归),例如上面示例中的
Properties.colors
,包括其中的Color.blue
和Color.red
标签?需要检查值的类型吗?
blue
和red
应该都被视为Properties
的成员吗?还是你想列出Properties.height
、Properties.weight
、Properties.colors.blue
和Properties.colors.red
? - chepnerProperties.height,Properties.weight,Color.blue,Color.red
运行。如果枚举嵌套更深,则迭代也应该通过这些值运行。@Samwise:我承认这个例子有点牵强,但我想尽可能保持简单。 - ctenarColor
有标签blue
和red
,Properties
有标签height, weight, colors
,但是我想将colors
解析为它自己的标签,即blue, red
。 - ctenarProperties
有一个名为height
的“枚举成员”,其值为'h'
。 - bad_coder