[Python-Dev] Replacement for print in Python 3.0

Martin Blais martin.blais at gmail.com
Mon Sep 5 17:16:40 CEST 2005

On 9/4/05, Stephan Deibel <sdeibel at wingware.com> wrote:
> On Sun, 4 Sep 2005, Guido van Rossum wrote:
> > But more important to me are my own experiences exploring the
> > boundaries of print.
> >
> > - I quite often come to a point in the evolution of a program where I
> > need to change all print statements into logging calls, or calls into
> > some other I/O or UI library. [...]
> FWIW, this almost always happens to me.  Although I've learned to
> avoid print in most cases, it was a somewhat painful lesson that seems
> quite at odds with how the rest of Python is designed -- usually,
> stuff just works and you aren't led into such design traps.

Happened to me too.

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.


More information about the Python-Dev mailing list