[Python-Dev] class name spaces inside an outer function
Ethan Furman
ethan at stoneleaf.us
Sun Apr 28 18:26:41 CEST 2013
On 04/27/2013 09:20 PM, Guido van Rossum wrote:
> On Saturday, April 27, 2013, Greg Ewing wrote:
>
>> class Planet(Enum):
>> MERCURY = (3.303e+23, 2.4397e6)
>> VENUS = (4.869e+24, 6.0518e6)
>> EARTH = (5.976e+24, 6.37814e6)
>> MARS = (6.421e+23, 3.3972e6)
>> JUPITER = (1.9e+27, 7.1492e7)
>> SATURN = (5.688e+26, 6.0268e7)
>> URANUS = (8.686e+25, 2.5559e7)
>> NEPTUNE = (1.024e+26, 2.4746e7)
>>
>> def __init__(self, mass, radius):
>> self.mass = mass
>> self.radius = radius
>
> If you want something like this, do you really have to inherit from Enum?
To answer your question:
Somewhere in the previous threads about enums a couple people had use-cases for an enum with extra attributes.
So, while you don't /have/ to enherit from Enum, if Enum provides the basics of what you need, and you can extend it
with the extra functionality that you need, why shouldn't you? (Not a rhetorical question -- I'm happy to learn
something I don't know.)
--
~Ethan~
More information about the Python-Dev
mailing list