I'm trying to change Python 2.7 code such that it can run both on 2.7 and 3.6 The obvious problem is print. It's called without parenthesis in 2.7 and with parenthesis in 3.6 So I tried runtime version detection (detection code taken from this answer):
def customPrint(line):
    if sys.version_info[0] < 3:
        print "%s" % line
    else:
        print( line )
and when I run this under Python 3.6 I get an error message saying
SyntaxError: Missing parenthesis in call to 'print'
So clearly Python tries to interpret all the code. That's different from PHP.
How do I have such custom implementation of print that it uses either print from Python 2 or from Python 3 depending on where it runs?
 
     
     
    