2006-11-23
python 中古怪的input()错误(已解决)
在windows下
这条语句
为什么我在 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 指的是什么 呢 ?
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 指的是什么 呢 ?
- 15:15
- 浏览 (2886)
- 论坛浏览 (3070)
- 评论 (2)
- 分类: python
- 发布在 Python 圈子
- 相关推荐
评论
在C的时代,\r只是回车,并不换行,如果你用打字机,那么\r的意思是指打字头回到行首,而非换到下一行。\r\n才是所有平台上公认的加车换行标记。Python是C语言写的,自然会这么想。呵呵。
已经解决,断点调试后显示,编译器每次都多读一个"/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
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
发表评论
该博客是同时发布到论坛的,无法评论在论坛已被锁定的帖子







评论排行榜