2016-02-12 64 views
0

在我的设置脚本中,我用了一年的函数现在突然中断。我剪切并粘贴成IPython的,看它是否是文件,但我得到的一般语法错误这里不仅是没有错误可见的,但用于工作中的作用并没有改变SyntaxError:从正在工作的函数中解析出意外的EOF

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='[email protected]') 
What is your work email? 
the default is [email protected] 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,和以前一样。为什么这会打破?谢谢

+0

的可能的复制[Python的意外EOF而解析](http://stackoverflow.com/questions/5074225 /蟒-意想不到-EOF·维持同时解析) –

回答

2

问题是

answer = input(text) 

在Python 2.7版要使用raw_input(...)而非input(...)

相关问题