PEP 354: Enumerations in Python
Ben Finney
bignose+hates-spam at benfinney.id.au
Tue Feb 28 19:50:17 EST 2006
Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> Ben Finney <bignose+hates-spam at benfinney.id.au> writes:
>> If an enumeration object were to be derived from, I would think it
>> just as likely to want to have *fewer* values in the derived
>> enumeration. Subclassing would not appear to offer a simple way to
>> do that.
>
> pentium_instructions = enum('add', 'sub', 'mul', ) # etc
>
> athlon64_instructions = enum('add64', 'sub64', # etc
> base_enum=pentium_instructions)
>
> # 386 has no floating point unit
> i386_instructions = enum(base_enum=pentium_instructions,
> remove=('addf', 'subf', 'mulf',)) # etc
These don't seem simple or elegant. I don't see a particular benefit
to doing it that way, rather than being explicit about manipulating
the member list::
pentium_instructions = enum('add', 'sub', 'mul')
athlon64_instructions = enum(
*[ str(i) for i in pentium_instructions] + ['add64', 'sub64'] )
i386_instructions = enum(
*[ str(i) for i in pentium_instructions
if i not in ['addf', 'subf', 'mulf'] ] )
I don't see a benefit to having the enum constructor grow extra
keyword arguments for operating on lists, when a list has its own
methods for doing so.
--
\ "A fine is a tax for doing wrong. A tax is a fine for doing |
`\ well." -- Anonymous |
_o__) |
Ben Finney
More information about the Python-list
mailing list