Python 2.7 print error print ()

I have a strange error with argument sep, file(etc.) python function print(). I tried to do this, peek into stackoverflow and read the python documentation , but I didn't come up with anything. I attached a simple snippet, I would deeply appreciate any help.

# python
Python 2.7.2 (default, Aug 19 2011, 20:41:43) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print("blah"*10, sep=" | ")
  File "<stdin>", line 1
    print("blah"*10, sep=" | ")
                        ^
SyntaxError: invalid syntax
+5
source share
3 answers

Try:

from __future__ import print_function

the first

+11
source

In the 2.x series printthere is an instruction, and in 3.x there is a function. If you want the 2.6+ function to have printas a function, you use the from __future__ import print_functionfirst import statement.

Wait for the code to break

+6
source

Python 3. :

from __future__ import print_function

, cdarke.

print , Python (print "Hello World").

0

All Articles