Are you sure you are using Python 3.x? Syntax is not available in Python 2.x because print is still an expression.
print("foo" % bar, end=" ")
in Python 2.x is identical
print ("foo" % bar, end=" ")
or
print "foo" % bar, end=" "
i.e. as calling print with a tuple as an argument.
This is clearly bad syntax (literals do not accept keyword arguments). In Python 3.x, print is a valid function, so it also takes keyword arguments.
The correct idiom in Python 2.x for end=" " :
print "foo" % bar,
(pay attention to the final comma, this makes it end the line with a space, not a line)
If you want more control over your output, consider using sys.stdout directly. This will not do any special magic with the exit.
Of course, in several recent versions of Python 2.x (2.5 should have it, not sure about 2.4), you can use the __future__ module to include it in your script file:
from __future__ import print_function
The same thing happens with unicode_literals and some other nice things (like with_statement ). This will not work in really old versions (i.e., Created before the function was introduced) Python 2.x.
Alan Plum Mar 16 2018-10-16T00: 00Z
source share