[Python-Dev] Replacement for print in Python 3.0

Stephan Deibel sdeibel at wingware.com
Mon Sep 5 18:56:59 CEST 2005


On Mon, 5 Sep 2005, Martin Blais wrote:
> However, there is an easy way out: hijack sys.stdout to forward to
> your logger system.
> I've got a web application framework that's setup like that right now,
> it works great (if you will not need the original print-to-stdout
> anymore in your program, that is).  I print, it goes to the logfile. 
> You just have to be careful where--in time-- you replace sys.stdout.

Sure, and indeed I've done that often enough but it's kind of ugly and 
doesn't help if you merge bodies of code where some stuff should go to 
a log, some to stdout, some elsewhere.

Hmm, maybe I'd end up avoiding the builtin print() as well, or at 
least need to pass around the stream where I want output.  The general 
problem of not tying code to a particular output stream is what I'm 
reacting to.

- Stephan



More information about the Python-Dev mailing list