problem with user confirmation
Matthew
ruach at chpc.utah.edu
Mon Sep 22 10:02:02 EDT 2003
That worked, thanks very much.
-matthew
"Duncan Smith" <buzzard at urubu.freeserve.co.uk> wrote in message news:<bkdfg7$lga$1 at news6.svr.pol.co.uk>...
> "Matthew" <ruach at chpc.utah.edu> wrote in message
> news:ec1162c7.0309181523.2077b7e5 at posting.google.com...
> > 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
>
> [snip]
>
> 'Y' evaluates to true.
>
> Maybe try something like:
>
> if confirm in ['y', 'Y', 'Yes', 'YES', 'yes']:
> etc.
>
> Duncan
More information about the Python-list
mailing list