how to write a html to automatically display the dictionary?

Tobiah toby at tobiah.org
Tue Sep 23 12:53:40 EDT 2014


On 09/23/2014 07:18 AM, luofeiyu wrote:
> x={'f1':1,'f2':2,'f3':3}
> how can i create the following html file automatically with python to display x ?
>
> <table border=1>
> <tr>
> <td>
> f1
> </td>
> <td>
> f2
> </td>
> <td>
> f3
> </td>
> </tr>
> <td>
> 1
> </td>
> <td>
> 2
> </td>
> <td>
> 3
> </td>
> <tr>
> </tr>
> </table>

def tablefy(values):
         print "<tr>"
         for value in values:
                 print "<td>%s</td>" % value
         print "</tr>"

x = {'f1': 1,'f2': 2,'f3': 3}

print "<table border=1>"
tablefy(x.keys())
tablefy(x.values())
print "</table>"





More information about the Python-list mailing list