Skip to content

Instantly share code, notes, and snippets.

@jacobb
Created August 14, 2012 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobb/3350554 to your computer and use it in GitHub Desktop.
Save jacobb/3350554 to your computer and use it in GitHub Desktop.
class Choice(object):
def __init__(self, *args):
self._data = tuple([
(value, value) if isinstance(value, str) else value
for value in args
])
self._data_dict = dict(self._data)
def __iter__(self):
return iter(self._data)
def __getattr__(self, name):
return self._data_dict.get(name)
YEAR_CHOICE = Choice(
('FR', 'Freshman'),
'SO',
'JR',
('SR', 'Senior'),
)
for x in YEAR_CHOICE:
print x
print YEAR_CHOICE.FR
print YEAR_CHOICE.JR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment