473,657 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with user confirmation

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(s elf, msg):
if not msg:
msg = 'Are you sure y/[n]> '
print msg
confirm = sys.stdin.readl ine()[:-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
Jul 18 '05 #1
3 1839

"Matthew" <ru***@chpc.uta h.edu> wrote in message
news:ec******** *************** ***@posting.goo gle.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(s elf, msg):
if not msg:
msg = 'Are you sure y/[n]> '
print msg
confirm = sys.stdin.readl ine()[:-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
Jul 18 '05 #2
At 05:39 PM 9/18/2003, Duncan Smith wrote:

"Matthew" <ru***@chpc.uta h.edu> wrote in message
news:ec******* *************** ****@posting.go ogle.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(s elf, msg):
if not msg:
msg = 'Are you sure y/[n]> '
print msg
confirm = sys.stdin.readl ine()[:-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.


To be more explicit:

given: confirm = 'y'
confirm == 'y' or 'Y' or 'Yes' or 'YES' or 'yes' evaluates to 1 (confirm ==
'y' returns 1)

but given: confirm = 'Y'
confirm == 'y' or 'Y' or 'Yes' or 'YES' or 'yes' evaluates to 'Y' (confirm
== 'y' returns 0 which is ored with 'Y" which is true, hence the result is 'Y')
Maybe try something like:

if confirm in ['y', 'Y', 'Yes', 'YES', 'yes']:


Even better

if 'yes'.startswit h(confirm.lower ()): # covers y ye yes Y YE YES yES Yes etc.

Bob Gailer
bg*****@alum.rp i.edu
303 442 2625
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003

Jul 18 '05 #3
That worked, thanks very much.

-matthew
"Duncan Smith" <bu*****@urubu. freeserve.co.uk > wrote in message news:<bk******* ***@news6.svr.p ol.co.uk>...
"Matthew" <ru***@chpc.uta h.edu> wrote in message
news:ec******** *************** ***@posting.goo gle.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(s elf, msg):
if not msg:
msg = 'Are you sure y/[n]> '
print msg
confirm = sys.stdin.readl ine()[:-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

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1843
by: Ronan | last post by:
Hi, I have a problem with a form using the PHP PEAR HTML_QuickForm package & javascript: I want to record the content of my form into a mySQL database then execute a javascript function. My problem is that javascript is executed before the mySQL insertion. I actually need the mySQL insertion first, since my javascript function
0
1067
by: Mike Grace | last post by:
Hi, I am writing a web site which sends order confirmations to users via email. Two changes that are needed are as follows: 1) PDF files are going to be attached to the email. It could be one, it could be 20! I have written the code to attach any number of PDF files to the
2
1109
by: pmud | last post by:
Hi, In my ASP.NET application, the user has to enter a large amount of data so that with submit button click all this information can go to SQL database.Wen the user clicks submit, he is redirected to the Confirmation page. For a certain number of records, data in half of the text boxes( which user has to enter) doesnt change. So, I have a text box where teh user enters the number of records in which the information in those half text...
0
2263
by: Suzanne | last post by:
I'd like to know how can I put up a confirmation question when the user tries to delete a row in the datagrid by clicking on the row header and pressing the Delete key? I have found this code on a windows forms FAQ site : Public Class DataGrid_Custom Inherits DataGrid Private Const WM_KEYDOWN = &H100
5
4881
by: Mark A. Sam | last post by:
Hello, I am sending two emails from the same procedure, one to myself (while testing) and another (a comfirmation) to the user on the website. I was having difficulty finding a relay server to SMTP though, but was able to do this though one of my personal account, Cabbage.Org. It doesn't make any sense to me why this works and no other account, including localhost and the remote server which hosts the website. Here is a code snippet...
2
2021
by: bienwell | last post by:
Hi all, I still have a problem when using Confirmation box in ASP.NET program. I need to get the value return of YES or NO from confirmation box in Sub function of VB program to do some tasks. For example, I have 2 text boxes and one button. The button will call On_Click event . Sub btnSelect_OnClick(ByVal sender As Object, ByVal e As EventArgs) Dim X as double = CDBL(txtbox1.text) Dim Y as double = CDBL(txtbox2.text)
1
3236
by: kang jia | last post by:
hi when user entered particulars in signuppage and click" signup" button, i will direct them to do_signup.php. if say the NRIC is dupicate in datebase, i will redirect them back to signup page again to re-signup, however, i would like to remain all the correct infromation, and let users re-entered their NRIC. how can i do this. can i use Session, but it seems cant work. any one can help me? my code in signup page is like this: ...
5
3203
by: jmartmem | last post by:
Greetings, I have built an Update Record Form in an ASP page. This form contains a number of fields, such as text boxes and menus, to name a few. Upon clicking the 'submit' button, I want the form values to pass to a confirmation page that shows the values entered and selected, with a CDONTS auto email generated at the same time. My problem is that I'm having trouble passing the values from the form to both the confirmation page and the...
28
4421
tdw
by: tdw | last post by:
Hi all, I am trying to add a feature to our database that automates sending emails. When entering a new order, I want the option to send an email to the company the order came from, attaching a copy of our work order. The file that I want to attach is a rich text document created by Access and stored on our server. The creation of this document is not the problem. The problem is getting the email option to work. It does not seem to...
0
8425
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8845
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.