24.6. IDLE¶
IDLE 是 Python 所内置的开发与学习环境。
IDLE 具有以下特性:
编码于 100% 纯正的 Python,使用名为
tkinter
的图形用户界面工具cross-platform: works mostly the same on Windows, Unix, and Mac OS X
提供输入输出高亮和错误信息的 Python 命令行窗口 (交互解释器)
提供多次撤销操作、Python 语法高亮、智能缩进、函数调用提示、自动补全等功能的多窗口文本编辑器
在多个窗口中检索,在编辑器中替换文本,以及在多个文件中检索(通过 grep)
提供持久保存的断点调试、单步调试、查看本地和全局命名空间功能的调试器
配置、浏览以及其它对话框
24.6.3. 启动和代码执行¶
Upon startup with the -s
option, IDLE will execute the file referenced by
the environment variables IDLESTARTUP
or PYTHONSTARTUP
.
IDLE first checks for IDLESTARTUP
; if IDLESTARTUP
is present the file
referenced is run. If IDLESTARTUP
is not present, IDLE checks for
PYTHONSTARTUP
. Files referenced by these environment variables are
convenient places to store functions that are used frequently from the IDLE
shell, or for executing import statements to import common modules.
In addition, Tk
also loads a startup file if it is present. Note that the
Tk file is loaded unconditionally. This additional file is .Idle.py
and is
looked for in the user’s home directory. Statements in this file will be
executed in the Tk namespace, so this file is not useful for importing
functions to be used from IDLE’s Python shell.
24.6.3.1. 命令行语法¶
idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
-c command run command in the shell window
-d enable debugger and open shell window
-e open editor window
-h print help message with legal combinations and exit
-i open shell window
-r file run file in shell window
-s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
-t title set title of shell window
- run stdin in shell (- must be last option before args)
如果有参数:
If
-
,-c
, orr
is used, all arguments are placed insys.argv[1:...]
andsys.argv[0]
is set to''
,'-c'
, or'-r'
. No editor window is opened, even if that is the default set in the Options dialog.Otherwise, arguments are files opened for editing and
sys.argv
reflects the arguments passed to IDLE itself.
24.6.3.2. IDLE-console differences¶
As much as possible, the result of executing Python code with IDLE is the
same as executing the same code in a console window. However, the different
interface and operation occasionally affect visible results. For instance,
sys.modules
starts with more entries.
IDLE also replaces sys.stdin
, sys.stdout
, and sys.stderr
with
objects that get input from and send output to the Shell window.
When this window has the focus, it controls the keyboard and screen.
This is normally transparent, but functions that directly access the keyboard
and screen will not work. If sys
is reset with reload(sys)
,
IDLE’s changes are lost and things like input
, raw_input
, and
print
will not work correctly.
With IDLE’s Shell, one enters, edits, and recalls complete statements.
Some consoles only work with a single physical line at a time. IDLE uses
exec
to run each statement. As a result, '__builtins__'
is always
defined for each statement.
24.6.3.3. 在没有子进程的情况下运行¶
By default, IDLE executes user code in a separate subprocess via a socket, which uses the internal loopback interface. This connection is not externally visible and no data is sent to or received from the Internet. If firewall software complains anyway, you can ignore it.
If the attempt to make the socket connection fails, Idle will notify you. Such failures are sometimes transient, but if persistent, the problem may be either a firewall blocking the connection or misconfiguration of a particular system. Until the problem is fixed, one can run Idle with the -n command line switch.
If IDLE is started with the -n command line switch it will run in a single process and will not create the subprocess which runs the RPC Python execution server. This can be useful if Python cannot create the subprocess or the RPC socket interface on your platform. However, in this mode user code is not isolated from IDLE itself. Also, the environment is not restarted when Run/Run Module (F5) is selected. If your code has been modified, you must reload() the affected modules and re-import any specific items (e.g. from foo import baz) if the changes are to take effect. For these reasons, it is preferable to run IDLE with the default subprocess if at all possible.
3.4 版后已移除.
24.6.4. 帮助和偏好¶
24.6.4.1. Additional help sources¶
IDLE includes a help menu entry called “Python Docs” that will open the extensive sources of help, including tutorials, available at docs.python.org. Selected URLs can be added or removed from the help menu at any time using the Configure IDLE dialog. See the IDLE help option in the help menu of IDLE for more information.
24.6.4.2. 偏好设定¶
The font preferences, highlighting, keys, and general preferences can be changed via Configure IDLE on the Option menu. Keys can be user defined; IDLE ships with four built-in key sets. In addition, a user can create a custom key set in the Configure IDLE dialog under the keys tab.
24.6.4.3. 扩展¶
IDLE contains an extension facility. Preferences for extensions can be changed with Configure Extensions. See the beginning of config-extensions.def in the idlelib directory for further information. The default extensions are currently:
FormatParagraph
AutoExpand
ZoomHeight
ScriptBinding
CallTips
ParenMatch
AutoComplete
CodeContext
RstripExtension