[fixing References field. Please reply in the original thread so I can find you easily.]
Roy Smith <[EMAIL PROTECTED]> writes: > If I have an enum, how can I verify that it's a legal value? Can I > do: > > Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat') > > def foo (day): > if day not in Weekdays: > raise ValueError The current PEP text doesn't specify; that's an omission on my part. The answer should be "yes, an enum can be tested for membership". I'll add that to the specification. > Also, do enums have __dict__ slots? Not specified as having one, no. > Can I do something like: > > day = 'sun' > print Weekdays.__dict__[day] You can do the same thing more elegantly by explicitly querying the attributes of the enumeration:: >>> day = 'sun' >>> print getattr(Weekdays, day) sun -- \ "There was a point to this story, but it has temporarily | `\ escaped the chronicler's mind." -- Douglas Adams | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list