question about getch()
Steve Holden
steve at holdenweb.com
Thu May 24 14:11:41 EDT 2007
gliquidsnake at hotmail.com wrote:
> Hey all,
>
> I'm having a problem with using msvcrt.getch() . What I want is some
> functionality like this:
>
> print 'blah blah blah, good_input to do blah blah blah, exit_key to exit'
>
> while input != exit_key:
> input = get_input_from_getch()
>
> if input == good_input:
> print input
> #do something
> if input == bad_input:
> #ask for new input
> if input == exit_key:
> pass
>
> so, if the user's input is good, the input is printed to the screen and
> the user is allowed to put in more input.
> if the user's input is bad, the input is not printed to the screen and
> python ignores the input.
> if the user presses a designated key then the program continues.
>
> for some reason, all I get when I try to implement getch() is python
> getting stuck in an infinite loop and printing "ΓΏ" continuously. I
> tried using msvcrt.kbhit() to wait for a key to be pressed before
> continuing to getch() but it seems the program then skips the loop entirely.
>
> I guess I just don't really understand how to use getch(). =(
>
More likely, you don't understand Python loops. Rather than "pass" in
the last option (which won't terminate the loop) try "break".
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------
More information about the Python-list
mailing list