SyntaxError:从正在运行的函数解析时出现意外的EOF

时间:2016-02-12 17:04:46

标签: python python-2.7 ipython python-2.x

在我的设置脚本中,我已经使用了一年的功能突然被打破了。我剪切并粘贴到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

这是func

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

我使用的是python 2,和以前一样。这为什么会破裂?谢谢

1 个答案:

答案 0 :(得分:2)

问题是

answer = input(text)

在python 2.7中,您希望使用raw_input(...)而不是input(...)