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


Groups > comp.lang.python > #78329 > unrolled thread

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

Started byPeter Otten <__peter__@web.de>
First post2014-09-25 08:44 +0200
Last post2014-09-25 08:44 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: how to make return(self.res) not to output the content of list ? Peter Otten <__peter__@web.de> - 2014-09-25 08:44 +0200

#78329 — Re: how to make return(self.res) not to output the content of list ?

FromPeter Otten <__peter__@web.de>
Date2014-09-25 08:44 +0200
SubjectRe: how to make return(self.res) not to output the content of list ?
Message-ID<mailman.14346.1411627499.18130.python-list@python.org>
luofeiyu wrote:

> `sys.displayhook = lambda obj: None ` will block everything to be
> displayed on the interactive python console .
> 
> i rewrite my code as the following :
> 
> import sqlite3,os,jinja2
> db = r'data.sqlite'
> con = sqlite3.connect(db)
> cur = con.cursor()
> 
> class status():
>       def __init__():
>           import sys
>           sys.displayhook=mydisplay
>       
>       def mydisplay(x):
>           if (x is not the result of an method grow of class status ) : x 
>           #how to do in python code? else : pass
>   
>       def grow(self):
>           self.res=  a data ananlyse process
>           return(self.res)
>      
>       def display(self):
>           #to display it in the html table
> 
> 
> 
> how to fulfill the mydisplay function in python code to make x.grow() in
> the following not to output the list of self.res??
> 
> 
> import analyse
> x=analyse.status()
> x.grow()

Have grow() return a list subclass with the empty string as its repr():

>>> class GrowMethodResult(list):
...     def __repr__(self): return ""
... 
>>> def grow():
...     return GrowMethodResult([1,2,3])
... 
>>> grow()

>>> 

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web