On Tue, Aug 6, 2013 at 6:33 PM, Ethan Furman <et...@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 -- http://mail.python.org/mailman/listinfo/python-list