In python, would the best way to keep a loop running until stopped by the user be as follows?
while not KeyboardInterrupt:
# The code I want repeated until I specify it to stop
break
I am new to code and would appreciate the help.
In python, would the best way to keep a loop running until stopped by the user be as follows?
while not KeyboardInterrupt:
# The code I want repeated until I specify it to stop
break
I am new to code and would appreciate the help.
How to kill a while loop with a keystroke?
Taken from Keith's answer
try:
while True:
do_something()
except KeyboardInterrupt:
pass
I suggest that you read up on exceptions and exception handling so you undertand what is different between the above and your posted code