从 python 中的枚举 class 中删除属性

Delete attributes from an enum class in python

我可以覆盖 delattrsetattr 以尝试删除或禁用枚举的某些属性 class,例如:

Class example(int, Enum):
     S1 = 1
     S2 = 2
     S3 = 3

  def __delattr__():
      # as default, we cannot delete an attribute like S3 from the enum class, but if
      #possible
      # i want this to remove S3

默认情况下您不能从枚举中删除属性,因为您不应该这样做。

枚举旨在 'provide a set of symbolic names bound to unique, constant values'

它们应该在您的程序中定义并被视为常量。

这是一种不好的做法,可能会导致错误,程序期望该属性存在但什么也没找到。

此外,请提供一些上下文,以便我们可以帮助建议替代方法

谢谢

显然,在我的用例中这样做,最好使用循环结构,提供更新列表并记住全局变量中的最后一个元素

import itertools

List = itertools.cycle(Updatedlist)