screen off?

Erik Max Francis max at alcyone.com
Mon Nov 25 16:18:29 EST 2002


Adam Hupp wrote:

> On Fri, 22 Nov 2002 21:49:06 +0000, Lance wrote:
> 
> > Some of my programs generate considerable screen output. I would
> > like to
> > turn off the screen output to save time while developing. Is there a
> > way to
> > do this, and turn it back on again?
> 
> You can do this by assigning a new file-like object to sys.stdout,
> i.e.
> 
> sys.stdout = open("/dev/null", "w")

If the original poster is already running a UNIX-like system, then
there's already an easier way to do this; redirect stdout to /dev/null
from the shell:

	./myScript.py > /dev/null

As for non-UNIX systems which wouldn't have a /dev/null to open anyway,
there's an easier work around; just create a file-like object that does
nothing:

	class NullFile:
	    def write(self, data): pass
	    def writelines(self, lines): pass
	    def flush(self): pass
	    def close(self): pass

and then

	sys.stdout = NullFile()

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Patriotism is the virtue of the vicious.
\__/ Oscar Wilde
    WebVal / http://www.alcyone.com/pyos/webval/
 URL scanner, maintainer, and validator in Python.



More information about the Python-list mailing list