Python 如何在 IDLE 中打开行号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18805203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 11:53:52  来源:igfitidea点击:

How to turn on line numbers in IDLE?

pythonpython-idle

提问by User

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?

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

采纳答案by ChrisProsser

Version 3.8 or newer:

3.8 或更新版本:

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

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

To show them automatically, go to Options> Configure IDLE> Generaland check the Show line numbers in new windowsbox.

要自动显示它们,请转到Options> Configure IDLE>General并选中该Show line numbers in new windows框。

Version 3.7 or older:

3.7 或以上版本:

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

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

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:

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

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

enter image description here

在此处输入图片说明

回答by Davos

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

有一组有用的 IDLE 扩展,称为 IDLEX,适用于 MacOS 和 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

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

回答by Martin Ghecea

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.

如果您试图追踪导致错误的行,如果您在显示行错误的 Python shell 中右键单击,它会出现一个“转到文件/行”,将您直接带到有问题的行.

回答by StahlRat

As it was mentioned by Davos you can use the IDLEX

正如达沃斯所提到的,您可以使用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:

碰巧我使用的是 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 = 

回答by Akshay Vilas Patil

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.

正如@StahlRat 已经回答了。我想为它添加另一种方法。Python 默认空闲编辑器Python Extensions Package 有扩展包

回答by Aaron

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

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

pip install IDLEX

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

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

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)

(感谢楼上的精彩回答)

回答by Terry Jan Reedy

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.

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

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.

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