Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: UNSURE 0.226 X-Spam-Level: ** X-Spam-Evidence: '*H*': 0.65; '*S*': 0.10; 'def': 0.12; 'stored': 0.12; '@property': 0.16; 'enum': 0.16; 'wrote:': 0.18; 'aug': 0.22; 'integer': 0.24; '2.0': 0.26; 'gets': 0.27; 'header:In- Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'factor': 0.31; 'class': 0.32; 'minimal': 0.33; 'skip:_ 10': 0.34; "i'd": 0.34; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'black': 0.61; 'arid': 0.84; 'desert': 0.84; 'ethan': 0.84; 'furman': 0.84; 'ocean': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=X5QC6Two24bIei5s/JJUrKJR7uK8H2f+GZHiPQBJbzE=; b=rCgQrTHf1WT9vElgfX+ibRhkCBhJ/dUzvoYI9sGF6HSF3k9eNuH6iHbtifDhzzo2Po Rh+nGuZS36n0KUmwsjFGOOQhm6Dh+VpzWFdgrEHOzN5tmAMt1zF95UtKCqkJANpS4kJO 3jmVpaY+7mDjQpciOUdLargsPoBAO1uKVrDfuXveE1YtvquNnXUr7O8DgfIifpAfjysG +yiSvNFK8raeDJvZLRth1dDMSJc3qeEWJYmMszn9z8JoTZWIuTQPc1JGbwR7rGts9TXq 43/k4ff2mxKAOuAGlUHStvx6f6TD7zYs52Ts+NpX5llhDjXqA8aQ685ybxukfhbdA6z3 OX8w== X-Received: by 10.68.213.5 with SMTP id no5mr2103819pbc.185.1375860968330; Wed, 07 Aug 2013 00:36:08 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <520195CC.7050506@stoneleaf.us> References: <520182F1.2060709@stoneleaf.us> <520195CC.7050506@stoneleaf.us> From: Ian Kelly Date: Wed, 7 Aug 2013 01:35:28 -0600 Subject: Re: Enum vs OrderedEnum To: Python Content-Type: text/plain; charset=ISO-8859-1 X-Mailman-Approved-At: Wed, 07 Aug 2013 10:12:49 +0200 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375863171 news.xs4all.nl 15873 [2001:888:2000:d::a6]:57602 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52116 On Tue, Aug 6, 2013 at 6:33 PM, Ethan Furman wrote: > class Environment(AutoNumber): > > gaia = 2.0 > fertile = 1.5 > terran = 1.0 > jungle = 1.0 > ocean = 1.0 > arid = 1.0 > steppe = 1.0 > desert = 1.0 > minimal = 1.0 > barren = 0.5 > tundra = 0.5 > dead = 0.5 > inferno = 0.5 > toxic = 0.5 > radiated = 0.5 > > def __init__(self, growth_factor): > self._growth_factor = growth_factor > > @property > def growth_factor(self): > return self._growth_factor > > This works because each Enum member gets its own integer value (1 - 15) in > __new__, plus a growth factor that is stored by __init__. Whether you think > this is better I have no idea. ;) Black magic, I like it. I think I'd write it like this, however: class Environment(AutoNumber): gaia = 2.0 fertile = 1.5 terran = jungle = ocean = arid = steppe = desert = minimal = 1.0 barren = tundra = dead = inferno = toxic = radiated = 0.5 def __init__(self, growth_factor): self.growth_factor = growth_factor