fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(fd) data = "stuff" # whatever it is you need doing return data finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)