簡體   English   中英

Python 2.7 print()錯誤

[英]Python 2.7 print() error

我使用python的print()函數的sepfile ,(etc)參數有一個奇怪的錯誤。 我試着把它谷歌出來,dag around stackoverflow,並閱讀python的文檔,但我沒有想到什么。 我附上了一個簡單的片段,我會非常感謝任何幫助。

# 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

嘗試:

from __future__ import print_function

第一

在2.x系列中, print是一個聲明,而在3.x中它是一個函數。 如果您希望在2.6+中將print作為函數,則使用from __future__ import print_function作為第一個import語句。

期待代碼打破

打印功能特定於Python 3.您有兩個解決方案:

from __future__ import print_function

所以你可以按照cdarke的規定使用它。

或者你使用print作為一個簡單的語句,因為它應該是舊版本的Python( print "Hello World" )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM