print as a function in 2.5 ?

Tino Wildenhain tino at wildenhain.de
Sun Apr 19 16:26:01 EDT 2009


Stef Mientki wrote:
> hello,
> 
> For several reasons I still use Python version 2.5.
> I understand that the print-statement will be replaced in Python version 
> 3.0.
> 
> At the moment I want to extend the print statement with an optional 
> traceback.
> So I've 2 options:
> 1- make a new function, like "eprint ()", where "e" stands for extended 
> print
> 2- make a function "print()" that has the extended features

There is a 3rd option: hook yourself in the output stream and just
climb the call stack in the write() method. This works (done that
myself for easy debugging)

The other way if you want to selectively do so, either use
a form of log (because why must it be print if the output
is debugging information?) or instead of hooking sys.stdout,
use another output stream and print >>debug, ... to it.

Regards
Tino



More information about the Python-list mailing list