diff options
| author | Damien George | 2014-01-25 00:17:36 +0000 |
|---|---|---|
| committer | Damien George | 2014-01-25 00:17:36 +0000 |
| commit | 7c9c667633d445e4df88868d630a0af4bc63d2f8 (patch) | |
| tree | b130d6dc98ba1ecd47d8886ea13048a88a5a6865 /tests | |
| parent | fcd4ae827171717ea501bf833a6b6abd70edc5a3 (diff) | |
py: Implement iterator support for object that has __getitem__.
Addresses Issue #203.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics/getitem.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/basics/getitem.py b/tests/basics/getitem.py new file mode 100644 index 000000000..f39296aca --- /dev/null +++ b/tests/basics/getitem.py @@ -0,0 +1,22 @@ +# create a class that has a __getitem__ method +class A: + def __getitem__(self, index): + print('getitem', index) + if index > 10: + raise StopIteration + +# test __getitem__ +A()[0] +A()[1] + +# iterate using a for loop +for i in A(): + pass + +# iterate manually +it = iter(A()) +try: + while True: + next(it) +except StopIteration: + pass |
