The rlcompleter Module

(Optional, Unix only) The rlcompleter module provides word completion for the readline module.

To enable word completion, just import this module. By default, the completion function is bound to the Esc key. Press Esc twice to finish the current word. To change the key, you can use something like:

import readline
readline.parse_and_bind("tab: complete")

The script in Example 14-10 shows how to use the completion functions from within a program.

Example 14-10. Using the rlcompleter Module to Expand Names

import rlcompleter
import sys

completer = rlcompleter.Completer()

for phrase in "co", "sys.p", "is":
 print phrase, "=>",
 # emulate readline completion handler
 for index in xrange(sys.maxint):
 term = completer.complete(phrase, index)
 if term is None:
 print term,

co => continue compile complex coerce completer
sys.p => sys.path sys.platform sys.prefix
is => is isinstance issubclass

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: