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


Groups > comp.lang.python > #52116 > unrolled thread

Re: Enum vs OrderedEnum

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2013-08-07 01:35 -0600
Last post2013-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.


Contents

  Re: Enum vs OrderedEnum Ian Kelly <ian.g.kelly@gmail.com> - 2013-08-07 01:35 -0600

#52116 — Re: Enum vs OrderedEnum

FromIan Kelly <ian.g.kelly@gmail.com>
Date2013-08-07 01:35 -0600
SubjectRe: 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web