2006年07月27日 星期四 10:49
程序如下(Python Tutorial Python3.7.1节):
def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
    while 1:
        ok = raw_input(prompt)
        if ok in ('y', 'ye', 'yes'):
            return True
        if ok in ('n', 'no', 'nop', 'nope'):
            return False
        retries = retries - 1
        if retries < 0:
            raise IOError, 'refusenik user'
        print complaint
while 1:
    flag = ask_ok('are you really want to quit?')
    if flag == True:
        break
print 'out'
在Eclipse里面不管输入什么,都输出Yes or no, please!
而在IDLE下面运行结果是正确的。
是Pydev的bug吗?
请教!
-- 
温铭
welcome to my blog : http://blog.csdn.net/wayne92
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060727/bf3d2d69/attachment.htm
2006年07月27日 星期四 11:06
在Eclipse里把OK的值打出来看看,可能输入的值被改动了。 On 7/27/06, Wayne <moonbingbing at gmail.com> wrote: > 程序如下(Python Tutorial Python3.7.1节): > def ask_ok(prompt, retries=4, complaint='Yes or no, please!'): > while 1: > ok = raw_input(prompt) > if ok in ('y', 'ye', 'yes'): > return True > if ok in ('n', 'no', 'nop', 'nope'): > return False > retries = retries - 1 > if retries < 0: > raise IOError, 'refusenik user' > print complaint > > while 1: > flag = ask_ok('are you really want to quit?') > if flag == True: > break > print 'out' > > 在Eclipse里面不管输入什么,都输出Yes or no, please! > 而在IDLE下面运行结果是正确的。 > 是Pydev的bug吗? > 请教! > -- > 温铭 > welcome to my blog : http://blog.csdn.net/wayne92 > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to > python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to > python-chinese-request at lists.python.cn > Detail Info: > http://python.cn/mailman/listinfo/python-chinese > > -- 缘分の天空 (QQ:7992118) ────────────────────────────── MSN : jiapj at hotmail.com BLog : http://spaces.msn.com/jiapj Flickr : http://www.flickr.com/photos/jiapj Picasa : http://picasaweb.google.com/jiapengjun ──────────────────────────────
2006年07月27日 星期四 11:22
设置断点后,发现问题处在哪儿了。
我输入一个字符串后按回车,所以ok的后面加了'\r'
将程序改为:
def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
    while 1:
        ok = raw_input(prompt)
        print ok
        if ok in ('y\r', 'ye\r', 'yes\r'):
            return True
        if ok in ('n\r', 'no\r', 'nop\r', 'nope\r'):
            return False
        retries = retries - 1
        if retries < 0:
            raise IOError, 'refusenik user'
        print complaint
while 1:
    flag = ask_ok('are you really want to quit?')
    if flag == True:
        break
print 'out'
在Eclipse里面运行结果正确。(当然,在IDLE里面运行就错了:(  )
看来在Eclipse和IDLE中对输入的处理不一样:Eclipse把回车既当作输入的结束符也当作了输入值的一部分;而IDLE只把回车当作输入的结束符。
2006/7/27, Peng Jun Jia <jiapengjun at gmail.com>:
>
> 在Eclipse里把OK的值打出来看看,可能输入的值被改动了。
>
>
-- 
温铭
welcome to my blog : http://blog.csdn.net/wayne92
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060727/748a5550/attachment-0001.htm
2006年07月27日 星期四 11:41
原来如此,学习! 2006/7/27, Wayne <moonbingbing at gmail.com>: > > 设置断点后,发现问题处在哪儿了。 > 我输入一个字符串后按回车,所以ok的后面加了'\r' > 将程序改为: > > def ask_ok(prompt, retries=4, complaint='Yes or no, please!'): > while 1: > ok = raw_input(prompt) > print ok > if ok in ('y\r', 'ye\r', 'yes\r'): > return True > if ok in ('n\r', 'no\r', 'nop\r', 'nope\r'): > > return False > retries = retries - 1 > if retries < 0: > raise IOError, 'refusenik user' > print complaint > > while 1: > flag = ask_ok('are you really want to quit?') > if flag == True: > break > print 'out' > 在Eclipse里面运行结果正确。(当然,在IDLE里面运行就错了:( ) > > 看来在Eclipse和IDLE中对输入的处理不一样:Eclipse把回车既当作输入的结束符也当作了输入值的一部分;而IDLE只把回车当作输入的结束符。 > > > 2006/7/27, Peng Jun Jia <jiapengjun at gmail.com>: > > > > 在Eclipse里把OK的值打出来看看,可能输入的值被改动了。 > > > > > -- > > 温铭 > welcome to my blog : http://blog.csdn.net/wayne92 > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -- 致 礼! 贺一丁 yiding.he at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060727/2cd907a3/attachment.html
2006年07月27日 星期四 11:54
ok= raw_input(prompt) 之后加一个 ok = ok.strip() 我这儿pydev1.2.1也有这个问题,看起来是对\r\n处理的不好吧 On 7/27/06, Wayne <moonbingbing at gmail.com> wrote: > 设置断点后,发现问题处在哪儿了。 > 我输入一个字符串后按回车,所以ok的后面加了'\r' > 将程序改为: > > def ask_ok(prompt, retries=4, complaint='Yes or no, please!'): > while 1: > ok = raw_input(prompt) > print ok > if ok in ('y\r', 'ye\r', 'yes\r'): > return True > if ok in ('n\r', 'no\r', 'nop\r', 'nope\r'): > > return False > retries = retries - 1 > if retries < 0: > raise IOError, 'refusenik user' > print complaint > > while 1: > flag = ask_ok('are you really want to quit?') > if flag == True: > break > print 'out' > 在Eclipse里面运行结果正确。(当然,在IDLE里面运行就错了:( ) > > 看来在Eclipse和IDLE中对输入的处理不一样:Eclipse把回车既当作输入的结束符也当作了输入值的一部分;而IDLE只把回车当作输入的结束符。 > > > 2006/7/27, Peng Jun Jia <jiapengjun at gmail.com>: > > 在Eclipse里把OK的值打出来看看,可能输入的值被改动了。 > > > > > > -- > > 温铭 > welcome to my blog : http://blog.csdn.net/wayne92 > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to > python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to > python-chinese-request at lists.python.cn > Detail Info: > http://python.cn/mailman/listinfo/python-chinese > >
Zeuux © 2025
京ICP备05028076号