Syntax problem - cannot solve it by myself

Ethan Furman ethan at stoneleaf.us
Tue Jun 8 18:18:31 EDT 2010


Deadly Dirk wrote:
> I am a total beginner with Python. I am reading a book ("The Quick Python 
> Book", 2nd edition, by Vernon Ceder) which tells me that print function 
> takes end="" argument not to print newline character. I tried and here is 
> what happens:
> 
>>>> print(x)
> abc
>>>> print(x,end="")
>   File "<stdin>", line 1
>     print(x,end="")
>                ^
> SyntaxError: invalid syntax
> 
> What does the error message mean? I am using Python 2.6.5 on Ubuntu 9.10. 

It means the book is written for Python 3.x.

You'll need a

from __future__ import print_function

before you can do the same in 2.6.  Not sure, but I seem to recall some 
very slight differences between the __future__ version of print and the 
actual version in 3.x (although, with my memory, it could easily be one 
of the other __future__ items).

~Ethan~



More information about the Python-list mailing list