Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78296
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'output': 0.05; 'method.': 0.07; 'sys': 0.07; '[1,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'template': 0.14; "'w')": 0.16; 'col': 0.16; 'lambda': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'res': 0.16; 'subject:make': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'skip:f 30': 0.19; '>>>': 0.22; 'input': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'code:': 0.26; 'header:X-Complaints-To:1': 0.27; '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; 'display': 0.35; 'add': 0.35; 'there': 0.35; '8bit%:80': 0.36; 'method': 0.36; 'list': 0.37; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:x 10': 0.40; 'how': 0.40; 'profile': 0.61; 'skip:w 30': 0.69; 'skip:r 30': 0.69; 'limit': 0.70; '8bit%:92': 0.71; '8bit%:100': 0.72; 'grow': 0.77; 'skip:\xe7 10': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: how to make return(self.res) not to output the content of list ? |
| Date | Wed, 24 Sep 2014 18:33:56 +0200 |
| Organization | None |
| References | <5422CD52.8060501@gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Gmane-NNTP-Posting-Host | p57bdb99b.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| 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.14321.1411576458.18130.python-list@python.org> (permalink) |
| Lines | 113 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1411576458 news.xs4all.nl 2845 [2001:888:2000:d::a6]:36211 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:78296 |
Show key headers only | View raw
luofeiyu wrote:
> 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 ?
You can set the display hook:
>>> [1, 2, 3]
[1, 2, 3]
>>> import sys
>>> sys.displayhook = lambda obj: None
>>> [1, 2, 3]
>>>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: how to make return(self.res) not to output the content of list ? Peter Otten <__peter__@web.de> - 2014-09-24 18:33 +0200
csiph-web