Enums and Python
Fred Gansevles
gansevle at cs.utwente.nl
Wed Jun 21 08:03:55 EDT 2000
In article <8iq78m$u5m$1 at nnrp1.deja.com>,
Fred Gansevles <gansevle at cs.utwente.nl> wrote:
>
> If you use enums only as a 'conveniant way to represent values', the
> next (quick-hack, untested) might be usefull:
>
> class Enum:
> def __init__(self, **kw):
> self.__dict__.update(kw)
>
> enum = Enum(Tag = 0, Date = 1, Ammount = 2)
>
> print "Date-field:", enum.Date
>
It just occured to me: If you'd like the enums to be 'global', you can
use the following (also-quick-but-even-dirtyer hack):
def enum(*kw):
globals().update(kw)
enum(Tag = 0, Date = 1, Ammount = 2)
print "Date-field:", Date
--
-----------------------------------------------------------------------
---- Linux/Windows-NT/IntraNetware Administrator ----
-- Whenever it sounds simple, I've probably missed something! ... Me --
-----------------------------------------------------------------------
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list