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


Groups > comp.lang.python > #52081

Re: Enum vs OrderedEnum

Date 2013-08-06 16:12 -0700
From Ethan Furman <ethan@stoneleaf.us>
Subject Re: Enum vs OrderedEnum
References <CALwzidm5LSH891oAvK_tzNBY5K-BNS-D970Pa_LLxZXWCb6O9w@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.281.1375830777.1251.python-list@python.org> (permalink)

Show all headers | View raw


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~

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web