Correct way to pause a Python program Correct way to pause a Python program python python

Correct way to pause a Python program


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 timeprint("something")time.sleep(5.5)    # Pause 5.5 secondsprint("something")


For Windows only, use:

import osos.system("pause")


So, I found this to work very well in my coding endeavors. I simply created a function at the very beginning of my program,

def pause():    programPause = raw_input("Press the <ENTER> key to continue...")

and now I can use the pause() function whenever I need to just as if I was writing a batch file. For example, in a program such as this:

import osimport systemdef pause():    programPause = raw_input("Press the <ENTER> key to continue...")print("Think about what you ate for dinner last night...")pause()

Now obviously this program has no objective and is just for example purposes, but you can understand precisely what I mean.

NOTE: For Python 3, you will need to use input as opposed to raw_input