SyntaxError: unexpected EOF while parsing from function that was working

SyntaxError: unexpected EOF while parsing from function that was working

在我的安装脚本中,我使用了一年的功能突然损坏了。我将它剪切并粘贴到 ipython 中以查看它是否是该文件,但我遇到了一个一般语法错误,其中不仅没有错误可见,而且曾经工作的功能也没有改变

In [8]: def gather(msg=None, default=None):
   ...:         while True:
   ...:                 text = msg + '\n'
   ...:                 if default:
   ...:                         text += "the default is {default}...press enter to accept\n".format(default=default)
   ...:                         answer = input(text)
   ...:                         return answer or default
   ...:                 answer = input(text)
   ...:                 if not answer:
   ...:                         continue
   ...:                 return answer
   ...:     

In [9]: EMAIL       = gather(msg='What is your work email?', default='me@example.com')
What is your work email?
the default is me@example.com...press enter to accept

  File "<string>", line unknown

    ^
SyntaxError: unexpected EOF while parsing

这是函数

def gather(msg=None, default=None):
    while True:
        text = msg + '\n'
        if default:
            text += "the default is {default}...press enter to accept\n".format(default=default)
            answer = input(text)
            return answer or default
        answer = input(text)
        if not answer:
            continue
        return answer

我用的是python2,和以前一样。为什么会这样?谢谢

问题是

answer = input(text)

在 python 2.7 中你想使用 raw_input(...) 而不是 input(...)