public
Created

apply patch to html_fibo.py

  • Download Gist
html_fibo.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
--- 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()
patched_html_fibo.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
 
"""
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()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.