Correct way to pause a Python program

RandomPhobia picture RandomPhobia · Jul 19, 2012 · Viewed 504.9k times · Source

I've been using the input function as a way to pause my scripts:

print("something")
wait = input("Press Enter to continue.")
print("something")

Is there a formal way to do this?

Answer

mhawke picture mhawke · Jul 19, 2012

It Seems fine to me (or raw_input() in Python 2.X). Alternatively, you could use time.sleep() if you want to pause for a certain number of seconds.

import time
print("something")
time.sleep(5.5)    # Pause 5.5 seconds
print("something")