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?
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:
Under the edit menu there is a go to line option (there is a default shortcut of Alt+G for this).
There is a display at the bottom right which tells you your current line number / position on the line:
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
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.
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 =
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.
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.
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)
C:\Python\Python37\pythonw.exe "C:\Python\Python37\Scripts\idlex.pyw"
saved as .bat on Windows? –
Vikki C:\Python\Python37\pythonw.exe "C:\Python\Python37\Scripts\idlex.pyw"
. done. –
Disturbed idlex.bat
file like what Python36\Lib\idlelib\idle.bat
does and create shortcut for idlex.bat
. –
Vikki © 2022 - 2024 — McMap. All rights reserved.