Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52116 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2013-08-07 01:35 -0600 |
| Last post | 2013-08-07 01:35 -0600 |
| 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.
Re: Enum vs OrderedEnum Ian Kelly <ian.g.kelly@gmail.com> - 2013-08-07 01:35 -0600
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2013-08-07 01:35 -0600 |
| Subject | Re: Enum vs OrderedEnum |
| Message-ID | <mailman.304.1375863171.1251.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web