Alex Rivera | Logout

Getting SyntaxError for print with keyword argument end=' '

Asked 2010-03-16T16:26:54.110
130

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.

Edit
Report

2 Answers

1

USE :: python3 filename.py

I had such error , this occured because i have two versions of python installed on my drive namely python2.7 and python3 . Following was my code :

#!usr/bin/python

f = open('lines.txt')
for line in f.readlines():
        print(line,end ='')

when i run it by the command python lines.py I got the following error

#!usr/bin/python

f = open('lines.txt')
for line in f.readlines():
        print(line,end ='')

when I run it by the command python3 lines.py I executed successfully

answered 2013-07-05T17:32:17.577
0

Even I was getting that same error today. And I've experienced an interesting thing. If you're using python 3.x and still getting the error, it might be a reason:

You have multiple python versions installed on same drive. And when you're presing the f5 button the python shell window (of ver. < 3.x) pops up

I was getting same error today, and noticed that thing. Trust me, when I execute my code from proper shell window (of ver. 3.x), I got satisfactory results

answered 2013-01-06T18:28:03.457

Your Answer