Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
apply patch to html_fibo.py
--- html_fibo.orig 2011-08-01 12:51:29.063696436 +0900
+++ html_fibo.py 2011-08-01 12:50:58.703267469 +0900
@@ -2,6 +2,8 @@
The most complicate ever way to produce an HTML list of fibonacci numbers
"""
+import gc
+
def fibo():
a, b = 1, 1
while True:
@@ -26,8 +28,10 @@
tag = HtmlTag(f, 4, 'li')
yield n
tag = None
+ gc.collect()
finally:
tag = None
+ gc.collect()
f.write('</ul>\n')
@@ -37,6 +41,8 @@
f.write('%d' % n)
if n > 100:
break
+ gc.collect()
+ f.close()
def main():
write_file()
"""
The most complicate ever way to produce an HTML list of fibonacci numbers
"""
import gc
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
gc.collect()
finally:
tag = None
gc.collect()
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
gc.collect()
f.close()
def main():
write_file()
content = open('fibo.txt').read()
print content
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.