On this page
  1. rlcompleter
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Wiring rlcompleter Into a Custom REPL
  7. Gotchas & Boundaries
  8. Classes & Objects

rlcompleter

Prev: resource | Up: stdlib_module | Next: runpy
Rel: string, re, difflib, textwrap, unicodedata
Ref: docs.python.org — rlcompleter
Tags: #public #python3 #stdlib


Import

import rlcompleter

Overview

Tab-completion provider (Completer) for the interactive Python REPL, hooking into readline to complete global names, keywords, and object attributes (obj.<Tab>). Use rlcompleter when embedding a custom Python console with code so users get standard Python tab completion.

Quick Start

import rlcompleter

comp = rlcompleter.Completer({"alpha": 1, "alphabet": 2, "beta": 3})
assert comp.complete("alp", 0) == "alpha"
assert comp.complete("alp", 1) == "alphabet"
assert comp.complete("alp", 2) is None

Implementation Walkthrough

1. Wiring rlcompleter Into a Custom REPL

Pass your console's locals dict to Completer(namespace) and bind it via readline.set_completer(comp.complete):

import rlcompleter

ns = {"items": [1, 2, 3]}
comp = rlcompleter.Completer(ns)
# Attribute completion on objects in ns:
assert comp.complete("items.app", 0) == "items.append("

Gotchas & Boundaries

Classes & Objects

Linked from

Related notes