⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 224.html

📁 Python Ebook Python&XML
💻 HTML
📖 第 1 页 / 共 2 页
字号:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Developer's Handbook -&gt; IDLE</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyN.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="8.html" class="navtitle">Web Development</a> &gt; <a href="0672319942.html" class="navtitle">Python Developer's Handbook</a> &gt; <a href="219.html" class="navtitle">16. Development Environment</a> &gt; <span class="nonavtitle">IDLE</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="223.html" title="Integrated Development Environments"><font size="1">&lt;&nbsp;BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=224" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="224.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="225.html" title="Pythonwin"><font size="1">CONTINUE&nbsp;&gt;</font></a></td></TR></TABLE>
<a href="6%2F1%2F2002+6%3A17%3A46+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>152015024128143245168232148039196038240039088173205162105045222217075242194030120015090</font><a href="read9.asp?bookname=0672319942&snode=224&now=6%2F1%2F2002+6%3A17%3A46+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT>
				<h3>


IDLE</h3>
				<p>IDLE is written in Python and it uses Tkinter for the GUI interface. IDLE is portable and available for all Python platforms that support Tkinter, which includes UNIX, Windows, and Macintosh. Because it is written in Python, you can extend it in Python as well. <a NAME="idx1073749608"></a>Guido van Rossum, along with many others including <a naME="idx1073749609"></A>Jeremy Hylton, <A name="idx1073749610"></A>Tim Peters, <A NAme="idx1073749611"></a>Moshe Zadka, and <a name="idx1073749612"></a>Mark Hammond are some of the people behind the development effort of the IDLE project. IDLE can be considered to be a fresh product because it was first released with version 1.5.2 of Python.</p>

				<div class="note"><p cLasS="notetitle"><b>Tip</b></p><P>

					<p>Some say that the name IDLE really comes from the surname of one of the actors who was part of the British troupe. Well, I don't know whether it is true or not.</p>

				</p></dIv>
<br>
<BR>

				<P>The IDLE environment consists of several distinct modules, and each one of them is responsible for a very specific functionality within the whole environment. There are modules to handle the undo engine, the colorizer, the automatic indentation, the class browser, the debugger, and many other features.</P>

				<p>The <a naME="idx1073749613"></A>
					<A name="idx1073749614"></A>undo engine dynamically intercepts all buffer-changing operations, stacking the inverse of the commands. This engine also supports grouping options, which is used by some high-level commands in order to undo/redo multiple operations simultaneously. It also tracks changes made in open files in order to ask you to save them before effectively letting you close them.</P>

				<P>The <A name="idx1073749615"></A>colorizer highlights Python syntax, and it works while IDLE is unoccupied. When you resume working, the colorizer stops.</P>

				<P>IDLE implements a powerful <A name="idx1073749616"></a>
					<a name="idx1073749617"></a>editor window, which gets subclassed when an instance of the interactive shell window is created to provide you access to the Python interactive mode. This subclass is able to handle the execution of commands, including the command history management.</p>

				<p>The editor window provides a set of functionality that allows you to create new files or browse through and edit existing Python scripts. Two other important <a name="idx1073749618"></a>
					<a NamE="idx1073749619"></a>browsing engines are also part of the IDLE environment: the <a nAme="idx1073749620"></a>
					<a Name="idx1073749621"></A>Path Browser and the Class Browser. The former is used for searching modules through the directories listed in the <TT Class="monofont">sys.path</TT> variable, whereas the latter implements a simple Class Browser for finding the methods of classes.<A Name="idx1073749622"></a>
					<A NAMe="idx1073749623"></a>
					<a nAME="idx1073749624"></A>
				</p>

				<p>IDLE also has a flexible search capability through its Find in Files dialog that lets you search through your files or the system files to find occurrences of identifiers or any other text fragments.</p>

				<p>A debugging implementation, which can be configured using the Debug Control Panel, is also offered by IDLE. Keep in mind that this Debug is still in the process of development and tuning.</p>

				<p>Among the features included in the latest release (version 0.5) of IDLE, I highlight the following ones:</p>

				<ul>
<li>
						<p>New functionality in the Shell window that displays <i>call tips</i> for functions that know the <i>documentation string.</i>
						</p>

					</li>
<lI>
						<p>New implementation for both the Path Browser and the Class Browser that is based on the tree widget navigation model. The Class and Path browsers now use a new version of the <tT claSs="monofont">pyclbr.py</tt> module, which is used to parse a Python file to recognize class and method definitions and to find out the superclasses of a class.</p>

					</Li>
<li>
						<P>Better auto-indent capabilities. It is now possible to set the indent width and toggle between the use of tabs in the indentation. Now, the auto-indent functionality knows how to indent the blocks inside multiline statements.</P>

					</LI>
<li>
						<p>You can now import files as modules and run them as scripts from the File Editor.</p>

					</LI>
<LI>
						<p>You can call IDLE with command-line arguments just as you normally do with the Python interpreter.</p>

					</li>
<LI>
						<P>A status bar was created to display the current line and column.</P>

					</li>
<li>
						<P>The Comment out region feature now inserts two hashes (<TT Class="monofont">##</tt>) in order to be more distinguishing.</p>

					</li>
</ul>
				<p>For more information, check out the following:</p>

				<blockquOte>
<P>
						<p>IDLE</p>

						<p><A targEt="_blank" hrEF="http://www.python.org/idle/">http://www.python.org/idle/</A>
						</P>

					</p>
<p>
						<p>IDLE-dev Mailing List</p>

						<P><A TArget="_blank" HREF="http://www.python.org/mailman/listinfo/idle-dev">http://www.python.org/mailman/listinfo/idle-dev</a>
						</p>

					</p>
</bLOCKquote>
				
					<h4>

Installing and Configuring IDLE</h4>
					<p>Previously, IDLE version 0.4 used to be automatically installed when you installed Python 1.5.2. The version 0.5, which is now available, can be downloaded from the IDLE page in the Python Web site. To install it, you just need to save the files in the <tt class="monofont">idle</tt> subdirectory of your current Python installation. Note that you can still keep your prior version by renaming it to something like <tt cLasS="monofont">idle 4.</tt>
						<a Name="idx1073749625"></a>
						<A namE="idx1073749626"></A>
						<A Name="idx1073749627"></a>
					</P>

					<P>In order to start IDLE on a Windows machine, you need to either access the IDLE icon on the Python Program's folder or double-click the file <TT clasS="monofont">idle.pyw,</TT> which is located in the idle subdirectory of your installation. Note that you need to have Tkinter perfectly installed on your system in order to use IDLE, which means that in order to use IDLE you need to have one installation of Tcl/Tk running on your system. (Multiple Tcl/Tk installations might confuse Python.)</P>

					<p>In order to run IDLE on a UNIX machine, first you need to obtain the source code, which usually is available along with the latest Python source code in the CVS tree梐 <a naME="idx1073749628"></A>
						<I>tarball</i> can also be downloaded from the IDLE homepage without any need to use CVS. Note that IDLE is part of most Python Distributions. Second, you just need to type <tt class="monofont">idle</tt> to open IDLE's Python Shell Window. For more information, check out</p>

					<blockquotE>
<p>
							<p>Python CVS Page</P>

							<p><a tArget="_blank" Href="http://www.python.org/download/cvs.html">http://www.python.org/download/cvs.html</A>
							</P>

						</P>
</BlockQUOTe>
				
				
					<h4>

Command Line Usage</h4>
					<p>The IDLE environment offers the following useful command-line arguments for your usage:</P>

					<PRE>
						
idle.py [-c command] [-d] [-e] [-s] [-t title] [args ...]
    -c command  run this command (see text below)
    -d          enable the debugger
    -e          edit mode (see text below)
    -s          run $IDLESTARTUP or $PYTHONSTARTUP first

    -t title    defines the title of the shell window
    args        arguments to be used

					</pre>

					<p>If <A NAMe="idx1073749629"></a>
						<a name="idx1073749630"></a>
						<tt class="monofont">-e</tt> is used, the arguments should be the files to be opened for editing. <tt cLasS="monofont">sys.argv</tt> receives the arguments passed to IDLE itself.</p>

					<P>If <a namE="idx1073749631"></a>
						<a nAME="idx1073749632"></A>
						<tt clASS="monofont">-c</Tt> is used, all arguments are placed in <tt cLASS="monofont">sys.argv[1:...],</tt> with <tt CLASs="monofont">sys.argv[0]</tt>  set to <tt class="monofont">'-c'.</tt>
					</p>

					<p>if neither <tt clasS="monofont">-e</tt> nor <Tt clAss="monofont">-c</tt> is used, the first argument is a script that is executed with the remaining arguments in <Tt clASS="monofont">sys.argv[1:...]</Tt> and <tt cLASS="monofont">sys.argv[0]</tt> set to the script name. If the script name is <tt CLASs="monofont">'-',</tt> no script is executed, but an interactive Python session is started; the arguments are still available in <tT CLAss="monofont">sys.argv.</tt>
						<a name="idx1073749633"></a>
						<a name="idx1073749634"></a>
						<a namE="idx1073749635"></a>
						<a Name="idx1073749636"></A>
						<a namE="idx1073749637"></a>
						<a nAME="idx1073749638"></A>
						<a namE="idx1073749639"></A>
					</P>

				
				
					<H4>

Python Shell</h4>
					<p>After calling the IDLE environment, the Python Shell Window pops up on the screen showing Python's interactive mode interface. As you can see, although you have the <a nAME="idx1073749640"></A>primary prompt <tt clASS="monofont">&gt;&gt;&gt;,</Tt> no secondary prompt (<tt class="monofont">...</tt>) is displayed. Sometimes, you might feel like, "Where is the prompt?" Or, the interpreter might appear to have stopped working in such a way that you cannot get a new prompt. The primary solution for these problems is to press CTRL+C in order to <a name="idx1073749641"></a>
						<a namE="idx1073749642"></a>
						<a Name="idx1073749643"></A>interrupt any running command, establish a keyboard interruption, and get back to the prompt. If you need to quickly get out of the <a namE="idx1073749644"></a>interpreter environment and close the Pythonwin window, press CTRL+D at the primary prompt.</p>

					<p>IDLE <A NAMe="idx1073749645"></a>
						<a nAME="idx1073749646"></A>colorizes the shell elements according to their logical meanings and syntax definitions. Note that while you are typing the code, definitions become blue, strings become green, keywords become orange, comments become red, the interpreter's standard output becomes blue, and the standard input becomes black. When you execute the code, the console outputs are displayed in brown and the standard error messages are in dark green (see <a hreF="224#4.html">Figure 16.1</A>. Observe that this figure, as all other figures shown in this book are not in color). This process happens in a background thread, and you can change the color scheme anytime you want just by editing the <TT clasS="monofont">ColorPrefs</TT> class in <Tt class="monofont">IdlePrefs.py</tt> file.</p>

					<center>
						<h5>
<a namE="4"></a>Figure 16.1. Note how IDLE uses colors to easily identify the various elements of the interface, such as the traceback messages.</h5>
						
							

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -