Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Handling yes/no questions from the User

Reply
Thread Tools

Handling yes/no questions from the User

 
 
claes_lillieskold@hotmail.com
Guest
Posts: n/a
 
      03-21-2006
I'm writing a scipt that need to interact with the user.
Lets say I have the:

"Do you want to continue [Y|n]"

Where just pressing return means Yes (since its uppercase).

Its easy to write a function for this, but perhaps something like this
already exists. Could someone point me to a class that handles this
kind of user interaction?

BR / Claes

 
Reply With Quote
 
 
 
 
dwelch
Guest
Posts: n/a
 
      03-21-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I'm writing a scipt that need to interact with the user.
> Lets say I have the:
>
> "Do you want to continue [Y|n]"
>
> Where just pressing return means Yes (since its uppercase).
>
> Its easy to write a function for this, but perhaps something like this
> already exists. Could someone point me to a class that handles this
> kind of user interaction?
>
> BR / Claes
>


I think a class would be overkill. I could see making this into a
reusable function perhaps.

I just use some code like this (with the '*' indicating the default):

ok = False
while True:
user_input = raw_input("\nUse this file (y=yes*, n=no, q=quit)
?").strip().lower()

if not user_input or user_input == 'y':
ok = True
break

elif user_input == 'q':
print "Exiting."
sys.exit(0)

elif user_input == 'n':
break

else:
print "Please enter 'y', 'n', or 'q'"


-Don
 
Reply With Quote
 
 
 
 
Steve
Guest
Posts: n/a
 
      03-22-2006
You need easygui:
http://www.ferg.org/easygui/index.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
signal handling and (structured) exception handling Peter C++ 34 10-17-2009 10:03 AM
python list handling and Lisp list handling Mark Tarver Python 22 04-26-2009 09:36 PM
Is faster handling hexadecimal values than handling chars? Iñaki Baz Castillo Ruby 1 04-15-2008 09:04 AM
Exception handling questions Gonçalo Rodrigues C++ 3 02-28-2005 02:24 AM
Re: Questions....questions....questions Patrick Michael A+ Certification 0 06-16-2004 04:53 PM



Advertisments