def getch():
 try:
  import msvcrt
  return msvcrt.getch()
 except ImportError:
  import sys
  import tty
  import termios
  fd = sys.stdin.fileno()
  old_settings = termios.tcgetattr(fd)
  try:
   tty.setraw(sys.stdin.fileno())
   ch = sys.stdin.read(1)
  finally:
   termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
  return ch

def getch ( ) : try : import msvcrt return msvcrt . getch ( ) except ImportError : import sys import tty import termios fd = sys . stdin . fileno ( ) old_settings = termios . tcgetattr ( fd ) try : tty . setraw ( sys . stdin . fileno ( ) ) ch = sys . stdin . read ( 1 ) finally : termios . tcsetattr ( fd , termios . TCSADRAIN , old_settings ) return ch
interrupting program until pressed any key .