Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52116
| 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 | 2013-08-07 01:35 -0600 |
| Subject | Re: Enum vs OrderedEnum |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.304.1375863171.1251.python-list@python.org> (permalink) |
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