Skip to content

Instantly share code, notes, and snippets.

@charlesreid1
Created May 6, 2017 01:07
Show Gist options
  • Save charlesreid1/5521aadc3cdb492f21b8799693a10c1b to your computer and use it in GitHub Desktop.
Save charlesreid1/5521aadc3cdb492f21b8799693a10c1b to your computer and use it in GitHub Desktop.
six.Iterator demo
$ python2 SixIteratorTest.py
1
2
3
4
5
6
7
8
$ python3 SixIteratorTest.py
1
2
3
4
5
6
7
8
$ python2 --version
Python 2.7.13
$ python3 --version
Python 3.6.1
import six
class Test(six.Iterator):
def __init__(self, init):
self.init = init
def __iter__(self):
return self
def __next__(self):
self.init += 1
return self.init
if __name__=="__main__":
x = Test(0)
for i,thing in enumerate(x):
print(thing)
if i>6:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment