Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52081 > unrolled thread

Re: Enum vs OrderedEnum

Started byEthan Furman <ethan@stoneleaf.us>
First post2013-08-06 16:12 -0700
Last post2013-08-06 16:12 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Enum vs OrderedEnum Ethan Furman <ethan@stoneleaf.us> - 2013-08-06 16:12 -0700

#52081 — Re: Enum vs OrderedEnum

FromEthan Furman <ethan@stoneleaf.us>
Date2013-08-06 16:12 -0700
SubjectRe: Enum vs OrderedEnum
Message-ID<mailman.281.1375830777.1251.python-list@python.org>
On 08/06/2013 04:00 PM, Ian Kelly wrote:

Use the .value attribute instead.  You could also substitute self for Environment.


> class Environment(Enum):
>
>      gaia = 1
>      fertile = 2
>      terran, jungle, ocean, arid, steppe, desert, minimal = range(3, 10)
>      barren, tundra, dead, inferno, toxic, radiated = range(10, 16)
>
>      def is_standard(self):
>          return self.terran.value <= self.value <= self.minimal.value
>
>      def is_hostile(self):
>          return self.barren.value <= self.value
>
>      @property
>      def growth_factor(self):
>          if self.is_standard():
>              return 1.0
>          elif self.is_hostile():
>              return 0.5
>          elif self is self.fertile:
>              return 1.5
>          elif self is self.gaia:
>              return 2.0
>          else:
>              raise AttributeError("Unknown growth_factor for %s" % self)

--
~Ethan~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web