Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! python2
- class Counter(object):
- def __init__(self, low, high):
- self.current = low
- self.high = high
- def __iter__(self):
- 'Returns itself as an iterator object'
- return self
- def next(self):
- 'Returns the next value till current is lower than high'
- if self.current > self.high:
- raise StopIteration
- else:
- self.current += 1
- return self.current - 1
- n = 1000
- #n = 10 # easier to check result
- i = Counter(0, n)
- for v in i:
- print(v)
- #------------------------------------------
- print('----------------------')
- i = Counter(0, n)
- print(next(i)) # 0
- print(next(i)) # 1
- print(next(i)) # 2
- #etc.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement