587
|
1 #!/usr/bin/env python
|
|
2 # -*- coding: utf-8 -*-
|
|
3
|
|
4 """
|
|
5 illustration of a class iterable
|
|
6 """
|
|
7 # XXX does not work!!@ TODO!!! XXX #
|
|
8
|
|
9 import argparse
|
|
10 import sys
|
|
11
|
|
12 class MyIterable(object):
|
|
13 def __init__(self, max):
|
|
14 self.items = list(range(max))
|
|
15 def __iter__(self):
|
|
16 return self
|
|
17 def next(self):
|
|
18 for i in self.items:
|
|
19 yield i
|
|
20
|
|
21 def main(args=sys.argv[1:]):
|
|
22
|
|
23 usage = '%prog [options]'
|
|
24 parser = argparse.ArgumentParser(usage=usage, description=__doc__)
|
|
25 options = parser.parse_args(args)
|
|
26
|
|
27 myiter = MyIterable(10)
|
|
28 for i in myiter:
|
|
29 print ('Hi {}'.format(i))
|
|
30
|
|
31 if __name__ == '__main__':
|
|
32 main()
|