PageRenderTime 397ms CodeModel.GetById 171ms app.highlight 6ms RepoModel.GetById 155ms app.codeStats 0ms

HTML | 222 lines | 175 code | 47 blank | 0 comment | 0 complexity | cba97f8525eb7d40b7a4495d65385ac7 MD5 | raw file
  1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2        "">
  3<html lang="en">
  5	<title>One Day of MacPython IDE Toying</title>
  6	<link rel="SHORTCUT ICON" href="../pythonsmall.gif">
  7	<META NAME="AppleIcon" CONTENT="../pythonsmall.gif">
  9<body bgcolor="#ffffff">
 10		<h1>One Day of MacPython IDE Toying</h1>
 11		<table>
 12		<tr>
 13			<td>
 14				<img src="IDE.gif" alt="">
 15			</td>
 16			<td>
 17				<p>This document gives a very basic introduction to the
 18				MacPython <b>I</b>ntegrated <b>D</b>evelopment <b>E</b>nvironment (IDE) on Mac OS. It was
 19				written specifically for MacPython 2.3 on Mac OS X, but most of
 20				it  is applicable to MacPython-OS9 too. It is based on 
 21				<a href="">&quot;One
 22				Day of IDLE Toying&quot;</a> by Danny Yoo, which you should read if
 23				you want to use the cross-platform IDLE Python development
 24				environment.</p>
 26			</td>
 27		</tr>
 28		</table>
 29		<hr>
 30		<br style="page-break-after: always">
 32<p>Ok, let's assume that we've already installed Python. (If not, we can
 33visit: <a href=""></a>
 34or <a href=""></a>
 35and download the most recent Python interpreter. Get the Mac OSX binary
 36installer.) The first thing we'd like to do is actually start running it!
 37We can do this by opening up the IDE, which should be in Applications
 38under the newly-created MacPython program folder: </p><p><img
 39src="loading_ide.gif" border=1 alt="image of IDE icon"></p>
 41<hr><br style="page-break-after: always">
 43<p>The IDE starts up and shows an interactive window: </p>
 44<p><img src="new_ide_window.gif" alt="image of new window"></p>
 46<p>If the window does not show up (because you have run the IDE before
 47and closed it: it remembers that between runs) open it with the <tt>Windows-&gt;Python Interactive</tt>
 48menu entry. </p>
 50<p>This is the interactive window to the IDE, it allows us to enter
 51commands directly into Python, and as soon as we enter a command,
 52Python will execute it and spit its result back to us.  We'll be
 53using this interactive window a lot when we're exploring Python: it's
 54very nice because we get back our results immediately.  If it helps,
 55we can think of it as a very powerful calculator.</p>
 57<hr><br style="page-break-after: always">
 59<p>Let's try something now!  As per tradition, let's get Python to say
 60the immortal words, "Hello World".  <img src="hello_world.gif"
 61border=1 alt="image of hello world program"></p> <p>Those '<tt>&gt;&gt;&gt;</tt>' signs act as a prompt
 62for us: Python is ready to read in a new command by giving us that
 63visual cue.  Also, we notice that as we enter commands, Python will
 64give us its output immediately.
 67<hr><br style="page-break-after: always">
 69<p>Ok, this seems pretty simple enough.  Let's try a few more
 70commands.  If we look below:</p>
 72<p><img src="simple_commands.gif" border=1 alt="image of command window"></p>
 74<p>we'll see the result of running a few more commands.  Don't worry
 75too much about knowing the exact rules for making programs yet: the
 76idea is that we can experiment with Python by typing in commands.  If
 77things don't work, then we can correct the mistake, and try it
 80<p>If you got to this point, you now know enough to start playing
 81around with Python!  Crack open one of the tutorials from the <a
 82href="">Python For Beginners</a> web
 83page, and start exploring with the interpreter.  No time limit here.  *grin*</p>
 85<hr><br style="page-break-after: always">
 87<p>Now that we've paddled long enough, we might be asking: ok, this is
 88neat, but if we close down Python and start it up again, how do we get
 89the computer to remember what we typed?</p>
 91<p>The solution is a little subtle: we can't directly save what's in
 92the interpreter window, because it will include both our commands and
 93the system's responses.  What we'd like is to make a prepared file,
 94with just our own commands, and to be able to save that file as a
 95document.  When we're in the mood, we can later open that file and
 96"run" Python over it, saving us the time of retyping the whole
 97thing over again.</p>
 99<p>Let's try this.  First, let's start with a clean slate by opening
100up a new window.</p> 
102<p><img src="making_new_window.gif" border=1 alt="image of making new window"></p>
104<p>Here's the result of that menu command:</p>
106<p><img src="new_window_made.gif" border=1 alt="image of new window"></p>
108<p>We notice that there's nothing in this new window.  What this means
109is that this file is purely for our commands: Python won't interject
110with its own responses as we enter the program, that is, not until we
111tell it to.  This is called an edit window, and it is very similar
112to edit windows in other editors such as TextEdit or BBEdit.</p>
114<hr><br style="page-break-after: always">
116<p>What we wanted to do before was save some of the stuff we had
117tried out on the interpreter window.  Let's do that by typing (or
118copy/pasting) those commands into our edit window.</p>
119<p><img src="entering_in_new_window.gif" border=1 alt="image of entering commands"></p>
121<p>Ok, we're done with copying and pasting.  
122One big thing to notice
123is that we're careful to get rid of the "<tt>&gt;&gt;&gt;</tt>"
124prompts because they're not really part of our program.  The
125interpreter uses them just to tell us that we're in the interpreter,
126but now that we're editing in a separate file, we can remove the
127artifacts that the interpreter introduces.
128I have added
129an extra empty print statement so our output ends with a newline.
132<hr><br style="page-break-after: always">
134<p>Let's save the file now.  The Save command is located under the <tt>File</tt> menu:</p>
135<p><img src="saving_edited_file.gif" border=1 alt="image of saving file"></p>
138<hr><br style="page-break-after: always">
140<p>Now that we've saved the program, how do we run the program? Use the
141Run All button at the top of the editing window, or the equivalent
142menu command <tt>Python-&gt;Run Window</tt>. The output will appear in a new
143window called Output Window. </p>
145<p>By the way, one thing to notice is that I made a typo: I didn't
146quite copy exactly what I had entered in the interpreter window
147before.  Does this affect things?</p>
149<p><img src="syntax_error.gif" border=1 alt="image of syntax error"></p>
151<p>Ooops.  Here is an example of what Python calls a "syntax error".
152Python sees that we made a typo, and warns us to take a much closer
153look at our program.  The designers of Python feel that having the
154system point out the error is better than trying to guess at what the
155programmer meant.  Press the Edit button and you will be brought to
156the trouble spot. </p>
158<p>Python is often perceptive enough to direct us toward the problem,
159and in this case, it's telling us that we forgot to put something at
160the end of this line.  In this case, we need to add a
161quotation mark at the end.  Let's add that in now.</p>
163<p>Other errors, which usually occur later, when your program has
164already done something, result in a different dialog that allows you
165to look at variables and such in addition to showing you where
166the error occurred. </p>
168<hr><br style="page-break-after: always">
170<p>Ok, let's say that we fixed that silly typo.  Let's try to run the
171program again. This gives us a new window, the Output window, showing
172the output of our program:</p>
173<p><img src="output_window.gif" border=1 alt="image of output window"></p>
175<hr><br style="page-break-after: always">
177<p>As we play with Python, we'll find ourselves "switching modes"
178between the Interpreter window and the edit window.  However,
179if we try anything more complicated than two or three lines it
180is often a good idea to work in an edit window. Align
181your edit and output window such that you can see them at the same time.</p>
183<p>This is pretty much all we need to know about the MacPython IDE to actually do
184interesting things.  There is a lot more to the IDE, here is a quick
185breakdown of things to see and explore:</p>
188	<li>All sorts of edit commands such as find and replace can be
189	used in the editor windows. See the <tt>Edit</tt> menu.</li>
191	<li>The bottom of the edit window has the scrollbar, but at the
192	left are two navigation devices: a line number box that you can type
193	numbers into to quickly go to a specific place, and a popup menu
194	that lists all classes, functions and methods in your file.</li>
196	<li>Above the vertical scrollbar you find another popup menu, this
197	influences how the Run command works. You should try the debugger
198	some time! If you do, and you wonder what the new small column on
199	the left of your script is: you can click in it to make Python stop
200	when it reaches this line so you can inspect things. The profiler
201	is also nifty: it shows you where your program is spending its time.</li>
203	<li>The module browser (<tt>Python-&gt;Module Browser</tt>) shows you all Python
204	modules currently loaded. You can look at the contents of the module with
205	Browse... and (for modules written in Python) at the source with Source...</li>
207	<li>The Package Manager (under the <tt>File</tt> menu, also available as a
208	separate application) allows you to easily install Python extension packages
209	for all sorts of things: scientific computation, image processing,
210	building user interfaces and more. </li>
212	<li>The <tt>Help</tt> menu gives you quick access to both the Python documentation,
213	if you have installed it with the Package Manager, and the Apple Developer
214	documentation. </li>
216	<li>The <tt>File-&gt;Save as Applet</tt> menu command saves your script as a MacOSX
217	application. This allows you to create a script that you can drop files on,
218	and much more. The IDE itself is such an applet, completely written in Python. </li>