Errors should never pass silently ... unless explicitly silenced.

Erik Max Francis max at alcyone.com
Fri Feb 7 21:04:33 EST 2003


Michele Simionato wrote:

> In Linux I am doing
> 
>   sys.stderr=file('/dev/null','w')
> 
> Is there a better way of doing that? I would be interested in a
> portable
> way, valid for Windows too.

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

	sys.stderr.close()
	sys.stderr = NullFile()

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Sometimes a cigar is just a cigar.
\__/ Sigmund Freud
    Official Omega page / http://www.alcyone.com/max/projects/omega/
 The official distribution page for the popular Roguelike, Omega.




More information about the Python-list mailing list