Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created July 10, 2013 14:07
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 shigemk2/5966572 to your computer and use it in GitHub Desktop.
Save shigemk2/5966572 to your computer and use it in GitHub Desktop.
# -*- coding: euc-jp -*-"
class MyIterator(object):
def __init__(self, step):
self.step = step
def next(self):
"""Returns the next element."""
if self.step == 0:
raise StopIteration
self.step -= 1
return self.step
# __next__ = next # Python3系用
def __iter__(self):
"""Returns the next element."""
return self
for el in MyIterator(4):
print(el)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment