[sapug] rlcompleters

Daryl Tester Daryl.Tester at iocane.com.au
Sun Feb 26 22:04:31 CET 2006

There was a thread in linuxsa recently(-ish) regarding
rlcompleter, which is a Python module you can import on
startup to allow command line completion.  I was poking
around for similar modules which allowed introspection
and found a (at the time broken) web site that has such
a module.  Now that the site is navigable again I present
to you -


The UI feels a little clunky to me (regards the default
namespace as empty when dir() shows it has attributes,
getting a function/method's signature is a little tricky
when auto-completing) but heck, you get the source code to
modify, and it retains the history between invocations
(saving it to ~/.pythonhist).  It's also aware of your
screen length, using tab to scroll the remainder of the
listing if necessary (making the tab key the next candidate
for wearing out quicker than other keys, apart from the
backspace :-).

Example (note the type info preceding the attribute name):

>>> import rlcompleter2; rlcompleter2.setup(); del rlcompleter2
Welcome to rlcompleter2 0.96
for nice experiences hit <tab> multiple times
>>> <TAB><TAB>
*error                           nothing found, empty namespace?
>>> __<TAB><TAB>
<boo>__debug__       : True, type: <type 'bool'>
<bui>__import__*(4)  -> module. Import a module.  The globals are only used
<mod>__builtins__    : <module '__main__' (built-in)>, type: <type 'module'
<non>__doc__         : None, type: <type 'NoneType'>
<str>__name__        : __main__, type: <type 'str'>

And printing out info from the docstring.

>>> __import__(<TAB><TAB>
0 ------------------------------------------------------------------------------
1 __import__(name, globals, locals, fromlist) -> module
3 Import a module.  The globals are only used to determine the context;
4 they are not modified.  The locals are currently unused.  The fromlist
5 should be a list of names to emulate ``from name import ...'', or an
6 empty list to emulate ``import name''.
7 When importing a module from a package, note that __import__('A.B', ...)
8 returns package A when fromlist is empty, but its submodule B when
9 fromlist is not empty.

  Daryl Tester, IOCANE Pty. Ltd.

More information about the sapug mailing list