【问题标题】:Get enumeration name by value [duplicate]按值获取枚举名称[重复]
【发布时间】:2016-12-07 13:31:17
【问题描述】:

有什么标准方法可以获取Enumeration names by value?

一个例子:

class Example(enum.Enum):
    one = 1
    two = 2

ex_variable = 1

给定ex_variable,能否获取Example.one.name中包含的字符串?

【问题讨论】:

    标签: python enums enumeration


    【解决方案1】:
    >>> Example(1).name
    'one'
    

    还有see the Python docs

    【讨论】:

    • 这很容易
    【解决方案2】:

    access the members of enums programatically

    >>> Example(ex_variable).name
    'one'
    

    【讨论】:

      猜你喜欢
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      • 2018-04-05
      • 2012-08-11
      • 1970-01-01
      相关资源
      最近更新 更多