equivalent of enum?

Ian Clarke I.Clarke at strs.co.uk
Tue Sep 14 09:16:03 EDT 1999


> In more direct answer to your question, there is no enum type in Python.
> It's simple enough to declare objects that you treat as constants, however:

I have always been a little dissatisfied with the way enums are normally
implemented, namely with an integer.  Why not make an "enum collection"
type (I am sure there must be a better name).  In essence this would be
an object which had several enums, say:

Sex: (male | female)
employed?: (yes | no)
os: (linux | windows | macos)

etc.  Normally these would be treated as 3 enums and would be stored as
three integers - 3 X 32 bits, or 96 bits, yet you can actually store
this data using just 4 bits (and that would contain a little bit of
redundancy).  The first bit would determine male or female, the second
bit employed or unemployed, and the third and fourth bits would store
the os.

In practice this could be implemented by creating an enum class.  We
could then create a function which takes an object containing enums (and
possibly allow these to be mixed with other data types) and compresses
the data bit by bit.  In the end we would get really efficient data
storage.  

Ok, so this is being somewhat anal, but I hate to see perfectly good
bytes go to waste :-)

Anyone got any comments on this idea?

Ian.

-- 
Ian Clarke                 "A subversive is anyone 
I.Clarke at strs.co.uk         who can out-argue
http://www.gnu.demon.co.uk/ their government"




More information about the Python-list mailing list