Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52116
| 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 | <ian.g.kelly@gmail.com> |
| 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 | <CALwzidm5LSH891oAvK_tzNBY5K-BNS-D970Pa_LLxZXWCb6O9w@mail.gmail.com> <520182F1.2060709@stoneleaf.us> <CALwzidmhKKnDssRd97zRHhDjmwvDRrXVr+5TW4Zfs1iKWFKnOA@mail.gmail.com> <520195CC.7050506@stoneleaf.us> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Wed, 7 Aug 2013 01:35:28 -0600 |
| Subject | Re: Enum vs OrderedEnum |
| To | Python <python-list@python.org> |
| 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 <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.304.1375863171.1251.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Tue, Aug 6, 2013 at 6:33 PM, Ethan Furman <ethan@stoneleaf.us> 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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Enum vs OrderedEnum Ian Kelly <ian.g.kelly@gmail.com> - 2013-08-07 01:35 -0600
csiph-web