The tty Module

(Unix only) The tty module contains some utility functions for dealing with tty devices. Example 12-9 shows how to switch the terminal window over to “raw” mode, and back again.

Example 12-9. Using the tty Module

File: tty-example-1.py

import tty
import os, sys

fileno = sys.stdin.fileno()

tty.setraw(fileno)
print raw_input("raw input: ")

tty.setcbreak(fileno)
print raw_input("cbreak input: ")

os.system("stty sane") # ...

raw input: this is raw input
cbreak input: this is cbreak input

Get Python Standard Library now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.