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

Thomas Heller theller@ctypes....
Tue Apr 7 14:11:33 CDT 2009


Jörgen Stenarson schrieb:
> 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:
[...]

Thanks.  In the meantime I have also found this out, but did not yet post
a reply to my question for the archives.
Anyway, my problem's not really solved completely because now I have the next
one, sorry ;-).

My Python console isn't started in the usual way because my application is
a Windows application.
When a certain button is pressed in the GUI, a win32 console is allocated,
sys.std[in|out|err] are initialized to readers/writers that read and write to
from/to the corresponding console handles, and so on.  Basically the code goes
like this:

    windll.kernel32.AllocConsole()
    windll.kernel32.SetConsoleTitleA(str(title))

    sys.stdout = writer(windll.kernel32.GetStdHandle(-11))
    sys.stderr = writer(windll.kernel32.GetStdHandle(-12))
    sys.stdin = reader(windll.kernel32.GetStdHandle(-10))

    from code import InteractiveConsole

    console = InteractiveConsole(ns)
    console.interact(title)

reader(handle) and writer(handle) are instances that read and write from/to
the console handles with the windll.kernel32.WriteConsole[A|W]()
and windll.kernel32.ReadConsoleW() windows functions.
So, is it possible to plug pyreadline into this system somehow?



-- 
Thanks,
Thomas



More information about the IPython-user mailing list