Mercurial > hg > config
annotate python/example/iterable.py @ 694:ebca6d85213a
File "/usr/lib/python3/dist-packages/IPython/config/__init__.py", line 16, in <module>
from .application import *
File "/usr/lib/python3/dist-packages/IPython/config/application.py", line 31, in <module>
from IPython.config.configurable import SingletonConfigurable
File "/usr/lib/python3/dist-packages/IPython/config/configurable.py", line 33, in <module>
from IPython.utils.text import indent, wrap_paragraphs
File "/usr/lib/python3/dist-packages/IPython/utils/text.py", line 28, in <module>
from IPython.external.path import path
File "/usr/lib/python3/dist-packages/IPython/external/path/__init__.py", line 2, in <module>
from path import *
File "/home/jhammel/python/path.py", line 25
print root(path)
^
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 09 Jul 2014 16:26:49 -0700 |
parents | e10d85ee0be3 |
children |
rev | line source |
---|---|
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() |