IDLE --- Python 編輯器與 shell

原始碼:Lib/idlelib/


IDLE 是 Python 的整合開發與學習環境 (Integrated Development and Learning Environment)。

IDLE 具有以下功能:

  • 跨平台:在 Windows、Unix 和 macOS 上的運作大致相同

  • Python shell window(互動式直譯器)提供有色彩的程式碼輸入、輸出和錯誤訊息

  • 多視窗文字編輯器,具有多次復原、Python 語法上色、智慧縮排、呼叫提示、自動完成等功能

  • 能在任何視窗中搜尋、編輯器視窗中取代文字,以及搜尋多個檔案 (grep)

  • 具有持久性斷點、能夠逐步執行和檢視全域和區域命名空間的除錯器

  • 設定、瀏覽器和其他對話框

The IDLE application is implemented in the idlelib package.

This is an optional module. If it is missing from your copy of CPython, look for documentation from your distributor (that is, whoever provided Python to you). If you are the distributor, see 可選模組的需求.

Editing and Navigation

Editor windows

IDLE may open editor windows when it starts, depending on settings and how you start IDLE. Thereafter, use the File menu. There can be only one open editor window for a given file.

The title bar contains the name of the file, the full path, and the version of Python and IDLE running the window. The status bar contains the line number ('Ln') and column number ('Col'). Line numbers start with 1; column numbers with 0.

IDLE assumes that files with a known .py* extension contain Python code and that other files do not. Run Python code with the Run menu.

Key bindings

The IDLE insertion cursor is a thin vertical bar between character positions. When characters are entered, the insertion cursor and everything to its right moves right one character and the new character is entered in the new space.

Several non-character keys move the cursor and possibly delete characters. Deletion does not puts text on the clipboard, but IDLE has an undo list. Wherever this doc discusses keys, 'C' refers to the Control key on Windows and Unix and the Command key on macOS. (And all such discussions assume that the keys have not been re-bound to something else.)

  • Arrow keys move the cursor one character or line.

  • C-LeftArrow and C-RightArrow moves left or right one word.

  • Home and End go to the beginning or end of the line.

  • Page Up and Page Down go up or down one screen.

  • C-Home and C-End go to beginning or end of the file.

  • Backspace and Del (or C-d) delete the previous or next character.

  • C-Backspace and C-Del delete one word left or right.

  • C-k deletes ('kills') everything to the right.

Standard keybindings (like C-c to copy and C-v to paste) may work. Keybindings are selected in the Configure IDLE dialog.

Automatic indentation

After a block-opening statement, the next line is indented by 4 spaces (in the Python Shell window by one tab). After certain keywords (break, return etc.) the next line is dedented. In leading indentation, Backspace deletes up to 4 spaces if they are there. Tab inserts spaces (in the Python Shell window one tab), number depends on Indent width. Currently, tabs are restricted to four spaces due to Tcl/Tk limitations.

See also the indent/dedent region commands on the