Created
August 14, 2012 16:11
-
-
Save jacobb/3350554 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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