In Python, what is the simplest and most Pythonic way to pause a loop where a user keypress would restart the loop? I’m looking at doing this just as a debugging aid, so that I can output some debug messages to stdout from within the loop without dumping a ton of text at once.
Share
If you are willing to limit the keypress to the Enter key, you can use
input(raw_inputin Python 2). Otherwise, you’ll need something platform specific.Alternatively, you could use
pdb, Python’s built in debugger.See also Python read a single character from the user.