print as a function in 2.5 ?
chambon.pascal at wanadoo.fr
Sun Apr 19 19:39:53 CEST 2009
I had found some article on this some months ago, can't remember where
But if you don't want harassments, I'd just advise you to create a
function with a properly specific name (like "exprint()"), and to make
it mimic closely the signature and behaviour of Py3k's print() function.
That way, if one day you switch to upper versions, a simple mass text
replacing operation on all your files will do it in an instant B-)
Stef Mientki a écrit :
> 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
> 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
> Now I guess that one of the reasons to change print from a statement
> to a function,
> is the option to override and extend it.
> If that's so, choice 2 would be the best choice.
> Is that assumption correct ?
> Suppose the second choice is the best,
> I can now create a function "print",
> and have the best of 2 worlds, get my extension and being prepared for
> the future.
> def print ( *args ) :
> for arg in args :
> print arg,
> print ('____________ Print Traceback ____________')
> do_extended printer actions
> Now doesn't seem to be allowed,
> nor is there an import from __future__ :-(
> What's the best solution (other than moving to 2.6 or up ?
> Stef Mientki
More information about the Python-list