问题:如何打开IDLE中的行号?

在IDLE的主外壳中,错误总是返回行号,但是开发环境甚至没有行号。反正有打开行号吗?

In the main shell of IDLE, errors always return a line number but the development environment doesn’t even have line numbers. Is there anyway to turn on line numbers?


回答 0

3.8版或更高版本:

要在当前窗口中显示行号,请转到,Options然后单击Show Line Numbers

要自动显示他们,去Options> Configure IDLE> General并检查Show line numbers in new windows框。

3.7版或更高版本:

不幸的是,尽管为此有一个增强请求,但没有选择在IDLE中显示行号。

但是,有两种方法可以解决此问题:

  1. 在编辑菜单下,有一个转到行选项(为此存在默认的Alt + G快捷键)。

  2. 右下角有一个显示,告诉您当前的行号/行的位置:

在此处输入图片说明

Version 3.8 or newer:

To show line numbers in the current window, go to Options and click Show Line Numbers.

To show them automatically, go to Options > Configure IDLE > General and check the Show line numbers in new windows box.

Version 3.7 or older:

Unfortunately there is not an option to display line numbers in IDLE although there is an enhancement request open for this.

However, there are a couple of ways to work around this:

  1. Under the edit menu there is a go to line option (there is a default shortcut of Alt+G for this).

  2. There is a display at the bottom right which tells you your current line number / position on the line:

enter image description here


回答 1

IDLE有一组有用的扩展,称为IDLEX,可与MacOS和Windows一起使用http://idlex.sourceforge.net/

它包括行号,我觉得它非常方便和免费。

否则,还有许多其他IDE,其中一些是免费的:https : //wiki.python.org/moin/IntegratedDevelopmentEnvironments

There’s a set of useful extensions to IDLE called IDLEX that works with MacOS and Windows http://idlex.sourceforge.net/

It includes line numbering and I find it quite handy & free.

Otherwise there are a bunch of other IDEs some of which are free: https://wiki.python.org/moin/IntegratedDevelopmentEnvironments


回答 2

如果您要查找导致错误的行,请在显示该行错误的Python shell中单击鼠标右键,它将显示“转到文件/行”,直接将您带到相关行。

If you are trying to track down which line caused an error, if you right-click in the Python shell where the line error is displayed it will come up with a “Go to file/line” which takes you directly to the line in question.


回答 3

正如达沃斯所说,您可以使用IDLEX

碰巧我正在使用Linux版本,并且从所有扩展名开始,我只需要LineNumbers。因此,我下载了IDLEX存档,从其中获取LineNumbers.py,将其复制到Python的lib文件夹(在我的情况下为/usr/lib/python3.5/idlelib),并将以下几行添加到主文件夹中的配置文件中: 〜/ .idlerc / config-extensions.cfg:

[LineNumbers]
enable = 1
enable_shell = 0
visible = True

[LineNumbers_cfgBindings]
linenumbers-show = 

As it was mentioned by Davos you can use the IDLEX

It happens that I’m using Linux version and from all extensions I needed only LineNumbers. So I’ve downloaded IDLEX archive, took LineNumbers.py from it, copied it to Python’s lib folder ( in my case its /usr/lib/python3.5/idlelib ) and added following lines to configuration file in my home folder which is ~/.idlerc/config-extensions.cfg:

[LineNumbers]
enable = 1
enable_shell = 0
visible = True

[LineNumbers_cfgBindings]
linenumbers-show = 

回答 4

行号已在两天前添加到IDLE编辑器中,并将出现在即将发布的3.8.0a3和更高版本的3.7.5中。对于新窗口,默认情况下它们处于关闭状态,但是可以在“设置”对话框的“常规”选项卡的“编辑器”部分将其撤消。对于现有窗口,在“选项”菜单上有一个新的“显示(隐藏)行号”条目。当前没有热键。可以通过单击一条线或单击并拖动来选择一条线或一组线。

有些人可能错过了“编辑/转到行”。右键单击上下文菜单转到文件/行可用于grep(在文件中查找)输出以及引用。

Line numbers were added to the IDLE editor two days ago and will appear in the upcoming 3.8.0a3 and later 3.7.5. For new windows, they are off by default, but this can be reversed on the Setting dialog, General tab, Editor section. For existing windows, there is a new Show (Hide) Line Numbers entry on the Options menu. There is currently no hotkey. One can select a line or bloc of lines by clicking on a line or clicking and dragging.

Some people may have missed Edit / Go to Line. The right-click context menu Goto File/Line works on grep (Find in Files) output as well as on trackbacks.


回答 5

由于@StahlRat已回答。我想为其添加另一种方法。有用于Python默认空闲编辑器Python扩展包的扩展包

As @StahlRat already answered. I would like to add another method for it. There is extension pack for Python Default idle editor Python Extensions Package.


回答 6

如上所述(一种快速的方法):

pip install IDLEX

然后,我在桌面(Win10)上创建一个快捷方式,如下所示:

C:\Python\Python37\pythonw.exe "C:\Python\Python37\Scripts\idlex.pyw"

路径可能不同,需要更改:

C:\Python\Python37

(感谢上面的精彩回答)

As mentioned above (a quick way to do this) :

pip install IDLEX

Then I create a shortcut on Desktop (Win10) like this:

C:\Python\Python37\pythonw.exe "C:\Python\Python37\Scripts\idlex.pyw"

The paths may be different and need to be changed:

C:\Python\Python37

(Thanks for the great answers above)


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。