Skip to content

Instantly share code, notes, and snippets.

@djfroofy
Created July 15, 2011 14:36
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 djfroofy/1084805 to your computer and use it in GitHub Desktop.
Save djfroofy/1084805 to your computer and use it in GitHub Desktop.
Making an iterable from __getitem__
# 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