Enums and Python

Geoff Talvola gtalvola at NameConnector.com
Wed Jun 21 16:42:23 EDT 2000


Fred Gansevles 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

A class can be used to do this quite nicely:

class MyEnum:
    Tag = 0
    Date = 1
    Amount = 2

print MyEnum.Date

--


- Geoff Talvola
  Parlance Corporation
  gtalvola at NameConnector.com






More information about the Python-list mailing list