[IPython-user] pyreadline, code.InteractiveConsole and tab completion on Windows

Jörgen Stenarson jorgen.stenarson@bostream...
Tue Apr 7 13:48:40 CDT 2009


Thomas Heller skrev:
> [repost from c.l.p]
> I have installed pyreadline, and get nice tab completion in
> the normal interactive interpreter:
...
> 
> However, in 'code.interact()', the behaviour is different.  Hitting TAB
> at the top level works as before, but hitting TAB after entering 'sys.' for example
> doesn't show any completions:
> 

I have put this question and an answer on launchpad 
https://answers.launchpad.net/pyreadline/+question/66759

Here's a copy of my answer:

The problem is that the completer function from rlcompleter only looks 
at the original namespace i.e. __main__.__dict__. When doing 
code.interact a new __dict__ is created as the global namespace for that 
session. The following session shows one way around the problem:

c:\python>python
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import code
 >>> code.interact()
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
 >>> import sys
 >>> sys.<TAB>
NOTHING HAPPENS
 >>> import readline
 >>> import rlcompleter
 >>> readline.set_completer(rlcompleter.Completer(globals()).complete)
 >>> sys.
sys.__displayhook__ sys.exc_info sys.path
sys.__doc__ sys.exc_type sys.path_hooks
sys.__egginsert sys.excepthook sys.path_importer_cache
sys.__excepthook__ sys.exec_prefix sys.platform
sys.__name__ sys.executable sys.prefix
sys.__plen sys.exit sys.ps1
sys.__stderr__ sys.exitfunc sys.ps2
sys.__stdin__ sys.getcheckinterval sys.setcheckinterval
sys.__stdout__ sys.getdefaultencoding sys.setprofile
sys._current_frames sys.getfilesystemencoding sys.setrecursionlimit
sys._getframe sys.getrecursionlimit sys.settrace
sys.api_version sys.getrefcount sys.stderr
sys.argv sys.getwindowsversion sys.stdin
sys.builtin_module_names sys.hexversion sys.stdout
sys.byteorder sys.last_traceback sys.subversion
sys.call_tracing sys.last_type sys.version
sys.callstats sys.last_value sys.version_info
sys.copyright sys.maxint sys.warnoptions
sys.displayhook sys.maxunicode sys.winver
sys.dllhandle sys.meta_path sys.__class__
sys.exc_clear sys.modules
 >>> sys.

/Jörgen


More information about the IPython-user mailing list