newbie : using python to generate web-pages
Eric Baker
google.com.112139 at satilla.com
Fri Nov 28 22:33:36 EST 2003
> I don't really think that 'print em(toto)' is more readable than
> 'print "<em>toto</em>"'. But that seems to be a matter of taste.
> I would always prefer the second way of writing HTML because I
> can see all the closing tags, indentation etc. Makes finding bugs
> easier.
True, using it like you descibed is not much of an innovation, but look at
this snippet:
import regsub, string, HTMLgen
doc = HTMLgen.SimpleDocument(title='Interrupts')
table = HTMLgen.Table(tabletitle='Interrupts',
border=2, width=100, cell_align="right",
heading=[ "Description", "IRQ", "Count" ])
table.body = [] # Empty list.
doc.append(table) # Add table to document.
interrupts_file = open('/proc/interrupts')
for line in interrupts_file.readlines():
data=regsub.split(string.strip(line),'[ :+]+')
table.body.append([ HTMLgen.Text(data[2]),data[0],data[1] ])
doc.write("interrupts.html")
Now that is much cleaner that a bunch of
print"<table><tr><td></td></tr></table>"
Eric
More information about the Python-list
mailing list