📄 25.html
字号:
<!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 -> The Shell Environment</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> > <a href="0672319942.html" class="navtitle">Python Developer's Handbook</a> > <a href="22.html" class="navtitle">2. Language Review</a> > <span class="nonavtitle">The Shell Environment</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="24.html" title="Language Review"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=25" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="25.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="26.html" title="Programs"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
<a href="5%2F31%2F2002+4%3A18%3A07+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>152015024128143245168232148039199167010047123209178152124239215162145081058108134082099064</font><a href="read6.asp?bookname=0672319942&snode=25&now=5%2F31%2F2002+4%3A18%3A07+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT>
<h3>
The Shell Environment</h3>
<p>The Python language is wrapped within a shell development environment. The main component of this shell is a <i>command line interpreter,</I> which is perfect for practicing, learning, and testing your programs.</P>
<H4>
Command Line Interpreter</H4>
<p>The command line interpreter is the heart of Python's shell environment. To <a naME="idx1073742028"></A>
<A name="idx1073742029"></A>
<A NAme="idx1073742030"></a>
<a name="idx1073742031"></a>access the command line interpreter, you need to switch to the prompt of your operating system. The following examples presume that the python directory is in your system's <tt class="monofont">path</tt> environment variable.</p>
<p>On a UNIX system, you must type</P>
<prE>
$ python
</pre>
<P>If you are running MS Windows, just say</p>
<pre>
c:\> python
</Pre>
<p>Note that in both cases, you just need to type the word <TT CLass="monofont">python;</tT> the rest is part of the shell prompt.</P>
<P>The Python for Windows installation also provides access to the command line interpreter by clicking its icon on the Start menu (see <A href="25#2.html">Figure 2.1</A>).<A NAme="idx1073742032"></a>
<a NAME="idx1073742033"></a>
<a name="idx1073742034"></a>
<a name="idx1073742035"></a>
</p>
<center>
<H5>
<a nAme="2"></a>Figure 2.1. By clicking on the Python (command line) icon, you gain access to the shell environment.</H5>
<img bOrdeR="0" WIDth="500" heIGHT="375" src="graphics/02fig01.gif" aLT="graphics/02fig01.gif">
</CEnter>
<P>After the command line interpreter is loaded (see <A HRef="25#3.html">Figure 2.2</a>), you can start coding your own programs.<a name="idx1073742036"></a>
<a name="idx1073742037"></a>
<a name="idx1073742038"></A>
</p>
<cEnteR>
<h5>
<a naMe="3"></a>Figure 2.2. Python's command line interface is now ready to use.</h5>
<IMG BordeR="0" WIDth="500" heIGHT="314" src="graphics/02fig02.gif" aLT="graphics/02fig02.gif">
</CEnter>
<p>Instead of using the command line interpreter, you can also use a graphical user interface called <tt class="monofont">IDLE</tt> (see <a href="25#4.html">Figure 2.3</a>).</P>
<ceNter>
<H5>
<a namE="4"></a>Figure 2.3.
<tt CLASs="monofont">IDLE</tt> is Python's GUI interpreter.</h5>
<IMG BordeR="0" WIDth="500" heIGHT="292" src="graphics/02fig03.gif" alt="graphics/02fig03.gif">
</center>
<div class="note"><P clAss="notetitle"><b>Note</B></p><p>
<p>See <a Href="219.html">Chapter 16, "Development Environment,"
</A> for details about using <TT Class="monofont">IDLE.</TT>
</P>
</P></div>
<bR>
<BR>
<P>As you can see by looking at the coding area in both <a hreF="25#3.html">Figures 2.2</A> and <A Href="25#4.html">2.3</a>, the interpreter's primary prompt is a <tt class="monofont">>>>.</tt>
</p>
<p>Let's start interacting with Python by running a variation of the standard <a name="idx1073742039"></A>
<a nAme="idx1073742040"></a>
<A name="idx1073742041"></A>
<a naME="idx1073742042"></A>
<Tt claSS="monofont">"hello world"</TT> program.</p>
<pre>
>>> print "Hello Python World"
Hello Python World
</PRE>
<P>The previous example demonstrates that the screen is the standard output device for commands that are typed in the interpreter's prompt. Next, another example is demonstrated. Note that the first command doesn't print anything because it is just an assignment operation. The result of the operation is passed to and stored at the informed variable. On the other hand, the second command has its output redirected to the standard output, which enables you to see the result of the operation.</p>
<pre>
>>> alfa = 3 + 2
>>> alfa * 4
20
</PRE>
<P>Python's <a name="idx1073742043"></a>
<a name="idx1073742044"></a>
<a name="idx1073742045"></a>syntax automatically indicates when a statement requires a subblock. The interpreter's secondary prompt <tt ClaSs="monofont">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -