[Edit]
If you read down to moerdns thread you will see that print() works in both versions. So my workaround is obsolete.
[/Edit]
Hi there,
I know some scripters are trying to write scripts that runn in 2.49 and 2.5x.
One of the problems is that print with 2.49 (Python 2.x) is a keyword while in BGE 2.53 (Python 3.x) print is a function.
That means all prints work work in one version but not the other.
There is a workaround. Unfortunatly need to replace all print statements :(. But you get a function that works in both versions.
Add this code to the initialization of your script:
# to make print available to Python 2 and 3
# just use cprint(...) instead of print ... or print(...)
cprint = globals()["__builtins__"]["print"]
this estalishes a new function cprint() (which means compatible print). This function is a reference to the builtin function (or keyword). It works with Python 2.x and Python 3.x making cprint running with both versions.
All you need to do is to replace
print "Hello world!"
with
cprint("Hello world")
By the way:
- you can call the function as you want, except “print”. This is a keyword in Python 2 and can’t be redefined there.
If I know a better method please post it here.
If you know methods to make other syntax changes compatible, let me know (here or in a separate thread), thanks :D.
I hope it helps
Monster