how to display the result in table with jinkoa2 temple?

luofeiyu elearn2014 at gmail.com
Wed Sep 24 03:29:23 CEST 2014


import sqlite3
db=r'F:\workspace\china\data\china.sqlite'
con=sqlite3.connect(db)
cur=con.cursor()
res=cur.execute('select 代码,所属行业,注册资本,雇员人数,管理人员人数 
from profile limit 20').fetchall()

the result is a list.

 >>> for row in res:
...     print(row)
...
('600000', '银行', '187亿', 39340.0, 30.0)
('600004', '民航机场', '11.5亿', 4499.0, 23.0)
('600005', '钢铁行业', '101亿', 38857.0, 24.0)
('600006', '汽车行业', '20.0亿', 10290.0, 20.0)
('600007', '房地产', '10.1亿', 2332.0, 19.0)
('600008', '公用事业', '22.0亿', 6515.0, 20.0)
('600009', '民航机场', '19.3亿', 5472.0, 18.0)
('600010', '钢铁行业', '80.0亿', 31389.0, 19.0)
('600011', '电力行业', '141亿', 37729.0, 29.0)
('600012', '高速公路', '16.6亿', 2106.0, 14.0)
('600015', '银行', '89.0亿', 25200.0, 34.0)
('600016', '银行', '340亿', 54927.0, 32.0)
('600017', '港口水运', '30.8亿', 5340.0, 21.0)
('600018', '港口水运', '228亿', 19842.0, 20.0)
('600019', '钢铁行业', '165亿', 37487.0, 23.0)
('600020', '高速公路', '22.5亿', 2959.0, 32.0)
('600021', '电力行业', '21.4亿', 6673.0, 22.0)
('600022', '钢铁行业', '64.4亿', 31738.0, 20.0)
('600023', '电力行业', '118亿', 10142.0, 14.0)
('600026', '港口水运', '34.0亿', 7536.0, 21.0)
 >>>

i want to display it in html table .

html_str='<table border=1>'
for row in res:
     html_str=html_str+'<tr>'
     for col in row:
         html_str=html_str+'<td>'+str(col).replace('\s','')
         html_str=html_str+'</td>'
     html_str=html_str+'</tr>'

html_str=html_str+'</table>'
myhtml=open('f:\\test.html','w')
myhtml.write(html_str)
myhtml.close()

when i open 'f:\\test.html'  in chrome ,



how can i change my code more elegantly with temple jinjia2 to do the 
same display ?




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140924/78d650d7/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ibbiefdi.png
Type: image/png
Size: 19642 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20140924/78d650d7/attachment.png>


More information about the Python-list mailing list