Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78267

how to display the result in table with jinkoa2 temple?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!border2.nntp.ams2.giganews.com!border1.nntp.ams2.giganews.com!backlog3.nntp.ams3.giganews.com!backlog3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <elearn2014@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status UNSURE 0.334
X-Spam-Level ***
X-Spam-Evidence '*H*': 0.35; '*S*': 0.02; 'col': 0.16; 'res:': 0.16; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; '&gt;&gt;&gt;': 0.24; 'code': 0.31; "skip:' 10": 0.31; 'skip:m 30': 0.32; 'open': 0.33; 'table': 0.34; 'subject:the': 0.34; 'subject:with': 0.35; 'display': 0.35; 'received:google.com': 0.35; '8bit%:80': 0.36; 'subject:?': 0.36; 'list.': 0.37; 'received:10': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'skip:\xc2 10': 0.60; 'subject: ': 0.61; 'profile': 0.61; 'more': 0.64; 'virus:src="cid:': 0.66; 'content-type:multipart/related': 0.67; 'limit': 0.70; '8bit%:100': 0.72; '8bit%:94': 0.72; 'received:10.32': 0.84; 'temple': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type; bh=q9l5sBi219rmli6lEDSYlRmNZ/pgeJbH026LpEZbHvc=; b=DW1cHy2NVI9qiyMoQ1v8Zbxe6Oe4iuo97y907y7cAwwYj2+Uw0eWPmdCP7VE0VpxAg jWofi0S7uygiOLvVdesF5wFHQESI+/SZpvf6toD0TGUz3kvFhEwcgwCMuyjqcBQNk6WQ oD/jkoE261KZsj5+vjzYwAGBOJ6OgIo7HtLFHVPSpTWjvMVbjPPJZCKIgSa9zEsITLQn 1uXnIGRjb2p6QL5QsaAtZ/sda9hL4EnGTnBLiOQdNHckChDb1EsLh1bjxpwQbL+VaDBp 7M83+PuQJQR9yZcfgRazseBcUbUvHjchgLnILRlNGi8wKnrNHO8rTEKTrfWD63AiWMKv aarw==
X-Received by 10.68.197.65 with SMTP id is1mr3148910pbc.125.1411522200910; Tue, 23 Sep 2014 18:30:00 -0700 (PDT)
Date Wed, 24 Sep 2014 09:29:23 +0800
From luofeiyu <elearn2014@gmail.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0
MIME-Version 1.0
To python-list@python.org
Subject how to display the result in table with jinkoa2 temple?
Content-Type multipart/alternative; boundary="------------060800030901020405050004"
X-Mailman-Approved-At Wed, 24 Sep 2014 09:20:34 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14299.1411543235.18130.python-list@python.org> (permalink)
Lines 517
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1411543235 news.xs4all.nl 2936 [2001:888:2000:d::a6]:34870
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78267
X-Original-Bytes 35275

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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 ?




Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

how to display the result in  table with jinkoa2 temple? luofeiyu <elearn2014@gmail.com> - 2014-09-24 09:29 +0800

csiph-web