1 # http://code.activestate.com/recipes/541096-prompt-the-user-for-confirmation/
3 def confirm(prompt=None, resp=False):
4 """prompts for yes or no response from the user. Returns True for yes and
7 'resp' should be set to the default value assumed by the caller when
8 user simply types ENTER.
10 >>> confirm(prompt='Create Directory?', resp=True)
11 Create Directory? [y]|n:
13 >>> confirm(prompt='Create Directory?', resp=False)
14 Create Directory? [n]|y:
16 >>> confirm(prompt='Create Directory?', resp=False)
17 Create Directory? [n]|y: y
26 prompt = '%s [%s]|%s: ' % (prompt, 'y', 'n')
28 prompt = '%s [%s]|%s: ' % (prompt, 'n', 'y')
31 ans = raw_input(prompt)
34 if ans not in ['y', 'Y', 'n', 'N']:
35 print 'please enter y or n.'
37 if ans == 'y' or ans == 'Y':
39 if ans == 'n' or ans == 'N':