M
Matthew
I am have written a medium sized program and everything works fine
except for one piece. At a certain point in the program I want to do a
simple user confirmation, eg Are you sure ? y/n. The problem that I am
having is that after the user enters an answer and presses enter, the
program executes the rest of the code regardless of what the user
response was.
Heres my code:
def confirmAction(self, msg):
if not msg:
msg = 'Are you sure y/[n]> '
print msg
confirm = sys.stdin.readline()[:-1]
print 'confirm = \'%s\'' %(confirm)
if confirm == 'y' or 'Y' or 'Yes' or 'YES' or 'yes':
return 1
return 0
if confirmAction('Are you sure you want to DEACTIVATE this port?
y/[n]'):
print 'Deactivating
#Do some other stuff
else:
sys.exit(-1)
At this point in the program I can enter nothing, or y, or sdfasd, and
no matter what I do it prints 'Deactivating and executes the rest of
my code. I can't figure it out to save my life. I am sure that the
answer is very simple and that I have just been thinking to hard and
have over looked it.
Thanks for any help
-matthew
except for one piece. At a certain point in the program I want to do a
simple user confirmation, eg Are you sure ? y/n. The problem that I am
having is that after the user enters an answer and presses enter, the
program executes the rest of the code regardless of what the user
response was.
Heres my code:
def confirmAction(self, msg):
if not msg:
msg = 'Are you sure y/[n]> '
print msg
confirm = sys.stdin.readline()[:-1]
print 'confirm = \'%s\'' %(confirm)
if confirm == 'y' or 'Y' or 'Yes' or 'YES' or 'yes':
return 1
return 0
if confirmAction('Are you sure you want to DEACTIVATE this port?
y/[n]'):
print 'Deactivating
#Do some other stuff
else:
sys.exit(-1)
At this point in the program I can enter nothing, or y, or sdfasd, and
no matter what I do it prints 'Deactivating and executes the rest of
my code. I can't figure it out to save my life. I am sure that the
answer is very simple and that I have just been thinking to hard and
have over looked it.
Thanks for any help
-matthew