changeset 587:e10d85ee0be3

dammit
author Jeff Hammel <k0scist@gmail.com>
date Thu, 23 Jan 2014 16:16:24 -0800
parents e14ba4fbc0e7
children 0a979b847461
files python/example/iterable.py
diffstat 1 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/example/iterable.py	Thu Jan 23 16:16:24 2014 -0800
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+illustration of a class iterable
+"""
+# XXX does not work!!@ TODO!!! XXX #
+
+import argparse
+import sys
+
+class MyIterable(object):
+    def __init__(self, max):
+        self.items = list(range(max))
+    def __iter__(self):
+        return self
+    def next(self):
+        for i in self.items:
+            yield i
+
+def main(args=sys.argv[1:]):
+
+    usage = '%prog [options]'
+    parser = argparse.ArgumentParser(usage=usage, description=__doc__)
+    options = parser.parse_args(args)
+
+    myiter = MyIterable(10)
+    for i in myiter:
+        print ('Hi {}'.format(i))
+
+if __name__ == '__main__':
+    main()