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


Groups > comp.lang.python > #78287

how to make return(self.res) not to output the content of list ?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!195.208.113.2.MISMATCH!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.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 OK 0.117
X-Spam-Level *
X-Spam-Evidence '*H*': 0.77; '*S*': 0.00; 'subject:not': 0.03; 'output': 0.05; 'method.': 0.07; 'def': 0.12; 'template': 0.14; "'w')": 0.16; 'col': 0.16; 'res': 0.16; 'subject:make': 0.16; 'subject: ?': 0.16; 'skip:f 30': 0.19; 'input': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'code:': 0.26; 'subject:) ': 0.29; 'subject:list': 0.30; "skip:' 10": 0.31; 'file': 0.32; 'class': 0.32; 'run': 0.32; 'open': 0.33; 'subject:the': 0.34; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; '8bit%:80': 0.36; 'method': 0.36; 'list': 0.37; 'received:10': 0.37; 'skip:o 20': 0.38; 'message-id:@gmail.com': 0.38; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; 'how': 0.40; 'skip:\xc2 10': 0.60; 'profile': 0.61; 'virus:src="cid:': 0.66; 'content- type:multipart/related': 0.67; 'skip:w 30': 0.69; 'skip:r 30': 0.69; 'limit': 0.70; '8bit%:92': 0.71; '8bit%:100': 0.72; '8bit%:94': 0.72; 'grow': 0.77; '&lt;/tr&gt;': 0.84; '&lt;table': 0.84; '&lt;tr&gt;': 0.84; 'received:10.32': 0.84; 'skip:\xe7 10': 0.84
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=LIlQ53teLnwMbcWC3ggpDjnmDnx8R2sEtC45HrQFUX8=; b=yLKtnKBma3Nx4r5bsCN4IbbX1d4rQ6OG3f+pBntlNQkROxEd1PBXAfcVtFewup8EDj 0Uud7on9TxhODpVezdUplJUAE4J+7DOOD03xTBTNnbUEiPoW3tJzjrEMbWfgDCq3YbxR kayg82hx9rzjLeDAdZXyURayBUjQ442l5wqyhvw40dh9Phn8PeGSgdNgC8CeFLpr2NWE n2ZRvQ6lcSPdU0ruQ5oRJA3hPz0kB/Yl0pPsKuLBoTNONb22/whdmXQZ+NDoeJHgyQaZ F6oTJy5qhjwDVYnMUlUZYhn2TNR5FYGzVVQo0r58yCdAQrOs4VWQ9LxaRBCcAQ90c8Sb e89A==
X-Received by 10.70.37.208 with SMTP id a16mr7741163pdk.147.1411566972977; Wed, 24 Sep 2014 06:56:12 -0700 (PDT)
Date Wed, 24 Sep 2014 21:55:30 +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 make return(self.res) not to output the content of list ?
Content-Type multipart/alternative; boundary="------------080007010605010502080309"
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.14312.1411566976.18130.python-list@python.org> (permalink)
Lines 474
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1411566976 news.xs4all.nl 2864 [2001:888:2000:d::a6]:47486
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78287

Show key headers only | View raw


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

There is a file named analyse.py in the D:\Python34\Lib\site-packages.


import sqlite3,os,jinja2
db = r'F:\workspace\china\data\china.sqlite'
con = sqlite3.connect(db)
cur = con.cursor()

class status():
     def grow(self):
         self.res=cur.execute('select 代码,所属行业,注册资本,雇员人数,管 
理人员人数 from profile limit 10').fetchall()

     def display(self):
         template = jinja2.Template('''
         <table border=1>
         {% for row in res %}
             <tr>
             {% for col in row -%}
                 <td>{{ col}}</td>
             {% endfor %}
             </tr>
         {% endfor %}
         </table>
         ''')
         with open('f:\\test.html', 'w') as f:
              f.write(template.render(res=self.res))
         import webbrowser
         webbrowser.open('f:\\test.html')


when i open python3.4  console to input  the code:
import analyse
x=analyse.status()
x.grow()
x.display()

i get


when i add  return(self.res) in grow method to make analyse.py into the 
following:

import sqlite3,os,jinja2
db = r'F:\workspace\china\data\china.sqlite'
con = sqlite3.connect(db)
cur = con.cursor()

class status():
     def grow(self):
         self.res=cur.execute('select 代码,所属行业,注册资本,雇员人数,管 
理人员人数 from profile limit 10').fetchall()
return(self.res)
     def display(self):
         template = jinja2.Template('''
         <table border=1>
         {% for row in res %}
             <tr>
             {% for col in row -%}
                 <td>{{ col}}</td>
             {% endfor %}
             </tr>
         {% endfor %}
         </table>
         ''')
         with open('f:\\test.html', 'w') as f:
              f.write(template.render(res=self.res))
         import webbrowser
         webbrowser.open('f:\\test.html')


now again input the code:
import analyse
x=analyse.status()
x.grow()
the x.grow() will output

[('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)]

now what i want to do is :
1.keep  return(self.res)  in grow method.
2.it is my target that when run  the code:

import analyse
x=analyse.status()
x.grow()

there is nothing output in my console ,  to make return(self.res) not to 
output the content of list ,
how can i do ?

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


Thread

how to make return(self.res) not to output the content of list ? luofeiyu <elearn2014@gmail.com> - 2014-09-24 21:55 +0800

csiph-web