Richer-Text I/O
The tools we have covered so far support the minimal subset of text I/O functionality that all platforms supply. Most platforms also offer richer-text I/O capabilities, such as responding to single keypresses (not just to entire lines of text) and showing text in any spot of the terminal (not just sequentially).
Python extensions and core Python modules let you access
platform-specific functionality. Unfortunately, various platforms
expose this functionality in different ways. To develop
cross-platform Python programs with rich-text I/O functionality, you
may need to wrap different modules uniformly, importing
platform-specific modules conditionally (usually with the
try
/except
idiom covered in
Chapter 6).
The readline Module
The readline
module
wraps the GNU Readline Library. Readline lets the user edit text
lines during interactive input, and also recall previous lines for
further editing and re-entry. GNU Readline is widely installed on
Unix-like platforms, and is available at http://cnswww.cns.cwru.edu/~chet/readline/rltop.html.
A Windows port (http://starship.python.net/crew/kernr/) is
available, but not widely deployed. Chris
Gonnerman’s module, Alternative Readline for
Windows, implements a subset of Python’s standard
readline
module (using a small dedicated
.pyd
file instead of GNU Readline) and can be
freely downloaded from http://newcenturycomputers.net/projects/readline.html.
When either readline
module is loaded, Python uses Readline for all line-oriented ...
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.