Created
July 15, 2011 14:36
-
-
Save djfroofy/1084805 to your computer and use it in GitHub Desktop.
Making an iterable from __getitem__
This file contains hidden or 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
# http://lucumr.pocoo.org/2011/7/9/python-and-pola/ | |
class NoWay(object): | |
def __getitem__(self, key): | |
if key == 0: | |
return 'a' | |
if key == 1: | |
return 'b' | |
if key == 'apple': | |
return 'c' | |
if key == 3: | |
return 'd' | |
raise IndexError('No key: %s' % key) | |
n = NoWay() | |
for i in n: | |
print i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment