If no raw_input: (Python question)
Is there a way to base operation of a loop based on whether or not a user has or has not inputted a value from the computer?
such as a: Code:
If no raw_input(): Rather, if they DID decide to hit enter, it would proceed with the rest of the if-else statement, thus skipping the process of the for loop and just continuing to render the rest of the complete message all at once. Thanks for reading :) x.D |
perhaps curses??
I was reading some information on the curses module for Python. I got a warm n' fuzzy reading about what it does, like perhaps this is what I was looking for:
Quote:
Applying that. I've tried defining a function that would take input discretely, but when I try to put that function into the other function that unfolds the text, my indenting gets all screwed up... I want to believe I'm on the right track, but I want even more to get this to work correctly: Here's a sample of what I've been toying with: Code:
import curses Is the curses module, in fact, what I am looking for? Or is it something simpler than that? This project ties into a previous thread, if you wish to see it, it is located here: http://www.linuxquestions.org/questi...ython-657725/? Thanks for your time, x.D |
Not exactly sure what you're doing (sorry, I didn't look at the other thread), but it seems like you want to check for loop exit condition by doing a non-blocking read from stdin--something like this:
Code:
import sys, os, select, time, termios Normally, the terminal doesn't `feed' the user's input to stdin until the user hits <ENTER>. One of the above termios operations turns that behavior off, so you get every key as the user types it. The other turns of echoing the input back to stdout, which it seems your interested in. I believe this can all be done through curses module, and it's probably more portable that way. Not that if you need to reset the terminal attributes back at the end (the finally clause). If you don't, use the command reset (you won't see it echoed) to reset the terminal. |
Now that I read your post a little closer, it seems you do not really care about the non-buffered input (not waiting for <ENTER>) and maybe not the non-echoed input, either. Here's a simpler example:
Code:
import sys, os, select, time |
I don't see much difference in this post with this one.
There is more than one way to do this. Of course, you can do this with curses if you choose to go down that route. Otherwise, you can do it with my original suggestion of using select and termios which DeuceNegative has already showed you here. Of course your write to stdout will be not work correctly after calling curses.initscr(). Continuing with our advice so far, a crude example: Code:
import time |
All times are GMT -5. The time now is 08:03 PM. |