Created
May 6, 2017 01:07
-
-
Save charlesreid1/5521aadc3cdb492f21b8799693a10c1b to your computer and use it in GitHub Desktop.
six.Iterator demo
This file contains hidden or 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
$ 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 |
This file contains hidden or 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
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