`
simohayha
  • 浏览: 1387690 次
  • 性别: Icon_minigender_1
  • 来自: 火星
社区版块
存档分类
最新评论

python 中古怪的input()错误(已解决)

阅读更多
在windows下
width = input('Please enter width: ') 


这条语句
为什么我在 IDLE下运行就是 正确的 而在pydev+eclipse 下,一运行然后输入 数字 打个回车就会出错呢? 只能用raw_input来代替.
错误显示  SyntaxError: unexpected EOF while parsing

文档中 This function is not safe from user errors! It expects a valid Python expression as input; if the input is not syntactically valid, a SyntaxError will be raised

在这里not syntactically 指的是什么 呢 ?
分享到:
评论
2 楼 moniker 2006-11-24  
在C的时代,\r只是回车,并不换行,如果你用打字机,那么\r的意思是指打字头回到行首,而非换到下一行。\r\n才是所有平台上公认的加车换行标记。Python是C语言写的,自然会这么想。呵呵。
1 楼 simohayha 2006-11-24  
已经解决,断点调试后显示,编译器每次都多读一个"/r",郁闷。

Fabio Zadrozny  的回答是:
Nope, this is a python bug mixed with a bad specification on how a shell is supposed to behave.

Usually shells put a '\n' when you press enter, but the Eclipse console puts '\r\n' and python does not handle it well, as this is not specified anywhere, and does not seem such awkward, my feeling is that it's a python bug, but you can surely argue the other way... so, you can submit a bug to eclipse.org and python.org and see who'll fix it... (or you can handle it in your program).

Cheers,

Fabio

相关推荐

Global site tag (gtag.js) - Google Analytics