PEP 354 -- "in" operator?

R

Roy Smith

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


Also, do enums have __dict__ slots? Can I do something like:

day = 'sun'
print Weekdays.__dict__[day]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top