I've created a simple reddit bot that reads comments in a specific subreddit.
for comments in reddit.subreddit(.........).comments(): # There is no comment limit so this is an infinite loop.
# Do stuff
I'd like the for loop to be broken out of, if the user presses a key. But I don't want the loop to stop and wait for any user input. I.e the loop iterates with or without any user input, but IF the user does enter a key, I'd the loop to be broken.
I've tried do these methods but I've not been able to get the desired result:
try:
for ........
# Do stuff
except KeyboardInterrupt:
pass
try:
while True:
for .........
# Do stuff
except KeyboardInterrupt:
pass
import msvcrt
for ........
# Do stuff
if msvcrt.kbhit():
break
I would prefer if there was no time.sleep() function required, as it would slow down the programme, but if there is no other way, it's fine.
Thanks.