Archive

Archive for June, 2010

Pausing the terminal in an OS independent way in Python

June 15th, 2010 jeremy No comments
import os
import sys
import tty
 
def pause():
    """ Prompt the user to press a key to continue. Should probably use a pager
    most of the time though.
    """
    if sys.platform in ('win32', 'win64'):
        os.system('PAUSE')
    elif sys.stdin.isatty():
        sys.stdout.write('Press any key to continue')
        tty.setraw(sys.stdin.fileno())
        try:
            sys.stdin.read(1)
        finally:
            os.system("stty sane")
 
print 'good times'
pause()
print 'CLOBBER\n' * 100
Categories: Python Tags: