From: Ethan Furman on
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~
From: Lie Ryan on
On 06/09/10 07:44, 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.

That print function is Python 3.x syntax. In Python 2.x, print is a
statement, not a function and uses completely different syntax.

You can, though, add this switch at the top of your python code:

from __future__ import print_statement

to use the new print syntax in python 2.x

Or, you could download and install Python 3.x.

Or, you could find a book that discusses Python 2.x.

From: Thomas Jollans on
On 06/09/2010 12:04 AM, Deadly Dirk wrote:
> On Tue, 08 Jun 2010 21:44:18 +0000, 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.
>>
>
> I figured it out. What I need is the following:
>
> "from __future__ import print_function" at the top of my script.
>
>
Yes, that will work, but you should really install Python 3.1 (it's in
ubuntu, as others have said!) because you will almost certainly hit into
other snags. Not as obvious as this one, but they are there. You can
work around all of them, of course, in one way or another...
>
>

From: Deadly Dirk on
On Wed, 09 Jun 2010 00:25:01 +0200, Thomas Jollans wrote:

> Yes, that will work, but you should really install Python 3.1 (it's in
> ubuntu, as others have said!) because you will almost certainly hit into
> other snags. Not as obvious as this one, but they are there. You can
> work around all of them, of course, in one way or another...

The book covers Python3 but my understanding was that it should also
cover Python 2.5 and 2.6.



--
The missionaries go forth to Christianize the savages -
as if the savages weren't dangerous enough already.
From: alex23 on
Deadly Dirk <d...(a)plfn.invalid> wrote:
> The book covers Python3 but my understanding was that it should also
> cover Python 2.5 and 2.6.

The "SECOND EDITION Covers Python 3" banner across the top of the
cover would seem to indicate otherwise. The first line of the About
section confirms it:

"This book is intended for people who already have experience in one
or more programming languages and want to learn the basics of Python 3
as quickly and directly as possible."

Unless you have a clear need for 3rd party libraries that currently
don't have 3.x versions, starting with Python 3 isn't a bad idea.