Generating HTML from python

Thomas Guettler guettli at thomas-guettler.de
Thu Jun 9 10:33:33 EDT 2005


Am Thu, 09 Jun 2005 12:43:19 +0000 schrieb Philippe C. Martin:

> Hi,
> 
> I wish to use an easy way to generate reports from wxPython and feel
> wxHtmlEasyPrinting could be a good solution.
> 
> I now need to generate the HTML wxHtmlEasyPrinting can print

I don't know wxPython, but generating HTML is very easy.

Some people say mixing HTML and programming code is not good.

But if you want to create dynamic pages with more logic than HTML
this is the best solution.

Example: Multiplication Table

rows=[]
heading=[]
for i in range(1, 11):
    heading.append('<th bgcolor="grey">%s</th>' % i)
    cols=[]
    for j in range(1, 11):
        cols.append('<td align="right">%s</td>' % (i*j))
    row='<tr><th bgcolor="grey">%s</th>%s</tr>' % (i, ''.join(cols))
    rows.append(row)
html="""
 <html>
  <head><title>Multiplication Table</title></head>
  <body>
   <table border="1">
    <tr>
     <th> </th> %s
    </tr>
    %s
   </table> 
  </body>
 </html> """ % (''.join(heading), ''.join(rows))

I guess this looks more ugly in most template languages.

 HTH,
   Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/





More information about the Python-list mailing list