When I try this code:
if Verbose:
print("Building internam Index for %d tile(s) ..." % len(inputTiles), end=' ')
I get a SyntaxError claiming that end=' ' is invalid syntax.
Why does this happen?
See What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python? for the opposite problem.
See Why is parenthesis in print voluntary in Python 2.7? for general consequences of Python 2’s treatment of print as a statement.
Are you sure you are using Python 3.x? The syntax isn’t available in Python 2.x because
printis still a statement.in Python 2.x is identical to
or
i.e. as a call to print with a tuple as argument.
That’s obviously bad syntax (literals don’t take keyword arguments). In Python 3.x
printis an actual function, so it takes keyword arguments, too.The correct idiom in Python 2.x for
end=" "is:(note the final comma, this makes it end the line with a space rather than a linebreak)
If you want more control over the output, consider using
sys.stdoutdirectly. This won’t do any special magic with the output.Of course in somewhat recent versions of Python 2.x (2.5 should have it, not sure about 2.4), you can use the
__future__module to enable it in your script file:The same goes with
unicode_literalsand some other nice things (with_statement, for example). This won’t work in really old versions (i.e. created before the feature was introduced) of Python 2.x, though.