[pypy-commit] extradoc extradoc: fibo program which depends on refcounting
antocuni
noreply at buildbot.pypy.org
Sun Jun 19 15:53:45 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: extradoc
Changeset: r3739:773f3e49ce7e
Date: 2011-06-19 15:54 +0200
http://bitbucket.org/pypy/extradoc/changeset/773f3e49ce7e/
Log: fibo program which depends on refcounting
diff --git a/talk/ep2011/training/src/html_fibo.py b/talk/ep2011/training/src/html_fibo.py
new file mode 100644
--- /dev/null
+++ b/talk/ep2011/training/src/html_fibo.py
@@ -0,0 +1,47 @@
+"""
+The most complicate ever way to produce an HTML list of fibonacci numbers
+"""
+
+def fibo():
+ a, b = 1, 1
+ while True:
+ yield a
+ a, b = b, a+b
+
+
+class HtmlTag(object):
+ def __init__(self, f, indent, tag):
+ self.f = f
+ self.tag = tag
+ self.f.write(' ' * indent)
+ self.f.write('<%s>' % tag)
+
+ def __del__(self):
+ self.f.write('</%s>\n' % self.tag)
+
+def html_fibo(f):
+ f.write('<ul>\n')
+ try:
+ for n in fibo():
+ tag = HtmlTag(f, 4, 'li')
+ yield n
+ tag = None
+ finally:
+ tag = None
+ f.write('</ul>\n')
+
+
+def write_file():
+ f = open('fibo.txt', 'w')
+ for n in html<_fibo(f):
+ f.write('%d' % n)
+ if n > 100:
+ break
+
+def main():
+ write_file()
+ content = open('fibo.txt').read()
+ print content
+
+if __name__ == '__main__':
+ main()
More information about the pypy-commit
mailing list