can someone tell me why this doesn't work please python 3
Scott David Daniels
Scott.Daniels at Acm.Org
Wed Jan 14 12:57:28 EST 2009
Gary M. Josack wrote:
> Ben Kaplan wrote:
>> On Jan 14, 2009, at 9:44 AM, "Gary M. Josack" <gary at byoteki.com> wrote:
>>> garywood wrote:
>>>> def ask_ok(prompt, retries=4, complaint="Yes or no, please!"):
>>>> while True:
>>>> password = input("enter something")
>>>> if password in ('y', 'ye', 'yes'): return True
>>>> if password in ('n', 'no', 'nope'): return False
>>>> retries = retries - 1
>>>> if retries < 0:
>>>> raise IOError('refusenik user')
>>>> print(complaint)
>>> Well since you didn't give an error I'm going to assume your problems
>>> are as follows:
>>> * Use raw_input() instead of input() # input evals the input received.
>>> * pass prompt as the argument to raw_input so that your prompt gets
>>> set # might want to give prompt a default value
>>> * password.lower() so Y, YE, YES, N, NO, NOPE also work for input
>> Did you miss the python 3 part? Raw_input was removed and input now
>> behaves like raw_input did in 2.x
> Ah, yes. Subject got truncated on my little laptop screen. Either way,
> more information is needed to diagnose the problem.
It is a bad idea to have post content exclusively in the headers.
Readers sometimes select by subject, but only read content.
However the answer the OP is looking for with his ill-formed
question could be revealed if his final print were:
print('%s on reply %r' % (complaint, password))
He'd realize he wanted:
password = input(prompt).rstrip()
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list