The termios Module

(Unix only, Optional) The termios module provides an interface to the Unix terminal control facilities. It can be used to control most aspects of the terminal communication ports.

In Example 12-8, this module is used to temporarily disable keyboard echo (which is controlled by the ECHO flag in the third flag field).

Example 12-8. Using the termios Module


import termios, TERMIOS
import sys

fileno = sys.stdin.fileno()

attr = termios.tcgetattr(fileno)
orig = attr[:]

print "attr =>", attr[:4] # flags

# disable echo flag
attr[3] = attr[3] & ~TERMIOS.ECHO

 termios.tcsetattr(fileno, TERMIOS.TCSADRAIN, attr)
 message = raw_input("enter secret message: ")
 # restore terminal settings
 termios.tcsetattr(fileno, TERMIOS.TCSADRAIN, orig)

print "secret =>", repr(message)

attr => [1280, 5, 189, 35387]
enter secret message:
secret => 'and now for something completely different'

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols


Multimedia Modules

Data Storage

Tools and Utilities

Platform-Specific Modules

Implementation Support Modules

Other Modules

Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh © 2008-2020.
If you may any questions please contact us: