Python 3.0 comes with a builtin print
function which breaks old code. In order to write code wich is compatible both with the 2.x series and with the 3.x series, I'm using the following Print
function
import sys
def Print(*values, **kwd):
fout = kwd.get("file", sys.stdout)
sep = kwd.get("sep", " ")
end = kwd.get("end", "\n")
w = fout.write
if values:
w(str(values[0]))
for v in values[1:]:
w(sep)
w(str(v))
w(end)
if sys.version_info[0] >= 3:
Print = eval("print")
In my programs, I use this Print
function as if it was 3.0's print. The difference is that it still runs with python 2.5, like in this example
Print("Hello", "world", sep="--", end=" !\n")
What do you you think of this ? Is there a better thing to do ?