简体   繁体   English

蟒蛇空闲。 自动完成/显示完成不起作用

[英]Python IDLE. Auto-complete/Show completions not working

IDLE is being very dodgy as to when it will actually show an Auto-complete menu. IDLE 对于何时实际显示自动完成菜单非常狡猾。 As of late it hasn't been working at all, or, more specifically, only works during an interactive session.最近它根本没有工作,或者更具体地说,只在交互式会话期间工作。

I've been using Code Blocks for C, and have gotten really used to the very nice auto-complete features, so it's a bit frustrating not having them -- especially while trying to learn a new frame work and what class is associated with which methods, etc, etc..我一直在使用 C 的代码块,并且已经真正习惯了非常好的自动完成功能,所以没有它们有点令人沮丧——尤其是在尝试学习一个新的框架工作以及与哪个类相关联时方法等等等等。

Is there an easy fix to get IDLE auto-complete working again?是否有一个简单的修复方法可以让 IDLE 自动完成功能再次工作? I'm using python version 2.7.我正在使用 python 2.7 版。

Is there perhaps a simple editor I should look into?也许我应该研究一个简单的编辑器? I've tried Vim, which was a little too heavy for my simple needs, Ninja, which I couldn't get to work for anything, and Sublime text 2, which I couldn't get my wxpython stuff to play with.我试过 Vim,它对于我的简单需求来说有点太重了,Ninja,我无法为任何东西工作,以及 Sublime text 2,我无法使用我的 wxpython 东西。 What would a nice option be?什么是不错的选择? Anything similar to Code Blocks would be cool, although, I'd be perfectly happy with IDLE if it would consistently work!任何类似于 Code Blocks 的东西都会很酷,不过,如果 IDLE 能够持续工作,我会非常满意!

REQUESTED CLARIFICATION: OK, so it seems I may have some of my terminology backwards.要求澄清:好的,看来我的一些术语可能倒退了。 By non-interactive, I mean, for instance, right clicking on a python file and selecting "edit with IDLE".非交互式,我的意思是,例如,右键单击一个 python 文件并选择“使用空闲编辑”。 This brings up what I guess could be described as a text editor.这带来了我猜可以被描述为文本编辑器的东西。 You can enter all you code here.您可以在此处输入所有代码。 Once ready, you then hit F5, or select Run, and it launches (what I've been referring to as) the interactive terminal.准备好后,然后按 F5,或选择运行,它会启动(我一直指的是)交互式终端。 It's here that you can type in code, press return, and instantly have that code evaluated.您可以在此处输入代码,按回车键,然后立即评估该代码。

What my question is referring to it the former, the part of IDLE where you edit the code.我的问题指的是前者,即您编辑代码的 IDLE 部分。 Sometimes while typing, after a .有时在打字时,在 . it will display the available methods, or after an open parenthesis it'll give hints as to the values expected.它将显示可用的方法,或者在一个左括号之后它会给出预期值的提示。 but the thing is, sometimes it does these things, sometimes it doesn't.但问题是,有时它会做这些事情,有时则不会。

The only thing i found so far is that if an editing session of IDLE is connected with python shell (called "interactive mode" in the question, ie after an attempt to run the edited script) then "non-interactive" IDLE can autocomplete based on values in interactive window.到目前为止我发现的唯一一件事是,如果 IDLE 的编辑会话与 python shell 连接(在问题中称为“交互模式”,即在尝试运行编辑后的脚本之后),那么“非交互式”IDLE 可以基于自动完成在交互式窗口中的值。 For example, if I type例如,如果我输入

a = [];
a.appen

and then hit < Tab > it will do nothing, but if I previously type然后点击 < Tab > 它什么也不做,但如果我以前输入

a = []

in corresponding python shell, IDLE will autocomplete correctly.在相应的 python shell 中,IDLE 将正确自动完成。

So my only suggestion is import same modules with same names in python shell window in order to make them "visible" for non-interactive IDLE editor.所以我唯一的建议是在 python shell 窗口中导入具有相同名称的相同模块,以使它们对非交互式 IDLE 编辑器“可见”。

I had the same problem with IDLE, because I want to learn Qt and therefore autocompletion is very useful.我在 IDLE 上遇到了同样的问题,因为我想学习 Qt,因此自动完成非常有用。

As it says in the settings of IDLE, you can trigger the autocomplete with "Control + Space" , eg after a "QtGui.".正如它在 IDLE 的设置中所说,您可以使用“Control + Space”触发自动完成,例如在“QtGui.”之后。 Then a menu opens where you can arrow-scroll through the entries.然后会打开一个菜单,您可以在其中箭头滚动浏览条目。

In my case, I had to open Options menu -> Extensions tab on the editor and look to make sure AutoComplete and other relevant options were enabled.就我而言,我必须在编辑器上打开选项菜单 -> 扩展选项卡,并确保启用自动完成和其他相关选项。 They actually were, but by just clicking on 'Apply' even though I dint have to change anything did the trick for me.他们实际上是,但只需单击“应用”,即使我必须更改任何内容,对我来说也是如此。

Sometimes it has to do with the time you have to wait to get a suggestions.有时这与您必须等待获得建议的时间有关。

When you go to options > extensions > general at completions popup wait you can change it to about 500ms.当您转到options > extensions > generalcompletions popup wait您可以将其更改为大约 500 毫秒。 In my case it was 2000ms by default.在我的情况下,默认为 2000 毫秒。

using the 'IDLE Editor window', you need to save and execute your code first.使用“空闲编辑器窗口”,您需要先保存并执行您的代码。 The application running, turn back to the Editor window to use the auto-completion.应用程序运行后,返回编辑器窗口以使用自动完成功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM