Created
July 10, 2013 14:07
-
-
Save shigemk2/5966572 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
# -*- 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