exit while loop with user prompt in python -
i've been browsing long time searching answer this.
i'm using python 2.7 in unix.
i have continuous while loop , need option user interrupt it, , after loop continue.
like:
while 2 > 1: items in hello: if "world" in items: print "hello" else: print "world" time.sleep(5) here user interrupt loop pressing "u" etc. , modify elements inside loop.
i started testing out raw_input, since prompts me out every cycle, it's don't need.
i tried methods mentioned here:
keyboard input timeout in python
couple of times, none of seem work how wish.
>>> try: ... print 'ctrl-c end' ... while(true): ... pass ... except keyboardinterrupt, e: ... print 'stopped' ... raise ... ctrl-c end stopped traceback (most recent call last): file "<stdin>", line 2, in <module> keyboardinterrupt >>>
obviously need replace pass whatever doing , print aftermath.
Comments
Post a Comment