Prev: capitalize() NOT the same as var[0].upper _ var[1:]
Next: [ANNC] pynguin-0.8 python turtle graphics application
From: Deadly Dirk on 8 Jun 2010 17:44 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. -- The missionaries go forth to Christianize the savages - as if the savages weren't dangerous enough already.
From: Peter Otten on 8 Jun 2010 17:54 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. There are small differences between Python 2.x and 3.x. print(x, end="") is Python 3 as is the whole book you are reading. I would guess that is prominently mentioned at the very beginning? For the examples to work you have to install Python 3.1 with $ sudo apt-get install python3 and invoke the interpreter with $ python3 Good luck with your efforts! Peter
From: fred lore on 8 Jun 2010 17:55 On 8 juin, 23:44, Deadly Dirk <d...(a)plfn.invalid> 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. in python 2.6.5, print is a keyword and this syntax is not allowed print becomes a real function with few keywords arguments like "end" only since python 3.0 Daniel
From: Robert Kern on 8 Jun 2010 17:58 On 6/8/10 5:44 PM, 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. The Quick Python Book is based on Python 3, which is a major upgrade from Python 2.6 and changed some parts of Python's syntax. In particular, it changed the print statement to a print() function. You can install Python 3 on Ubuntu using the python3 package. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
From: Deadly Dirk on 8 Jun 2010 18:04 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. -- The missionaries go forth to Christianize the savages - as if the savages weren't dangerous enough already.
|
Next
|
Last
Pages: 1 2 3 4 Prev: capitalize() NOT the same as var[0].upper _ var[1:] Next: [ANNC] pynguin-0.8 python turtle graphics application |