【问题标题】:How can I make my python script wait until I tell it it to continue in the terminal?如何让我的 python 脚本等到我告诉它在终端中继续?
【发布时间】:2016-03-13 04:44:34
【问题描述】:

我试图让第二个打印语句等到我在命令行中按 Enter 键,但我不断收到意外的 EOF 错误。

print "hi"
continu = input("Press Enter to continue!")
print "hi"

这是我的回溯

Traceback (most recent call last):
  File "save_cookies.py", line 2, in <module>
    continu = input("Press Enter to continue!")
  File "<string>", line 0

    ^
SyntaxError: unexpected EOF while parsing

【问题讨论】:

  • 你是如何运行你的脚本的?我的意思是python save_cookies.py?
  • 您使用的是哪个 python 版本?看起来您正在混合使用 python2 和 python3 语句
  • @AyushShanker 我在 geany 中按 F5。
  • 是的,您使用的是哪个 Python 版本?
  • 如果您使用的是 Python 2.x,请将 input 更改为 raw_input

标签: python command-line terminal


【解决方案1】:

您似乎在混合使用 python2python3 语句。

对于python2,您需要使用raw_input (PEP 3111):

print "hi"
raw_input("Press Enter to continue!")
print "hi"

对于python3,您需要调整print (PEP 3105) 上的语法:

print("hi")
input("Press Enter to continue!")
print("hi")

【讨论】:

    【解决方案2】:

    尝试使用raw_input() 而不是input()

    【讨论】:

      猜你喜欢
      • 2014-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多