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


Groups > comp.lang.python > #52081

Re: Enum vs OrderedEnum

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'attribute': 0.07; '%s"': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'def': 0.12; '16)': 0.16; '@property': 0.16; 'substitute': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'instead.': 0.24; '2.0': 0.26; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; 'class': 0.32; 'minimal': 0.33; 'could': 0.34; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'environment.': 0.39; 'to:addr:python.org': 0.39; 'ian': 0.60; 'received:173': 0.61; 'received:69.56': 0.68; 'received:69.56.224': 0.84; 'received:69.56.224.20': 0.84; 'received:gateway02.websitewelcome.com': 0.91
Date Tue, 06 Aug 2013 16:12:49 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version 1.0
To python-list@python.org
Subject Re: Enum vs OrderedEnum
References <CALwzidm5LSH891oAvK_tzNBY5K-BNS-D970Pa_LLxZXWCb6O9w@mail.gmail.com>
In-Reply-To <CALwzidm5LSH891oAvK_tzNBY5K-BNS-D970Pa_LLxZXWCb6O9w@mail.gmail.com>
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender ([173.12.184.233]) [173.12.184.233]:48266
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.281.1375830777.1251.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375830777 news.xs4all.nl 15894 [2001:888:2000:d::a6]:51304
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52081

Show key headers only | 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