/Mac/Resources/app/Resources/English.lproj/Documentation/ide/index.html

http://unladen-swallow.googlecode.com/ · 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. "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
  3. <html lang="en">
  4. <head>
  5. <title>One Day of MacPython IDE Toying</title>
  6. <link rel="SHORTCUT ICON" href="../pythonsmall.gif">
  7. <META NAME="AppleIcon" CONTENT="../pythonsmall.gif">
  8. </head>
  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="http://www-hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/">&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>
  25. </td>
  26. </tr>
  27. </table>
  28. <hr>
  29. <br style="page-break-after: always">
  30. <p>Ok, let's assume that we've already installed Python. (If not, we can
  31. visit: <a href="http://www.cwi.nl/~jack/macpython.html">http://www.cwi.nl/~jack/macpython.html</a>
  32. or <a href="http://python.org">http://python.org</a>
  33. and download the most recent Python interpreter. Get the Mac OSX binary
  34. installer.) The first thing we'd like to do is actually start running it!
  35. We can do this by opening up the IDE, which should be in Applications
  36. under the newly-created MacPython program folder: </p><p><img
  37. src="loading_ide.gif" border=1 alt="image of IDE icon"></p>
  38. <hr><br style="page-break-after: always">
  39. <p>The IDE starts up and shows an interactive window: </p>
  40. <p><img src="new_ide_window.gif" alt="image of new window"></p>
  41. <p>If the window does not show up (because you have run the IDE before
  42. and closed it: it remembers that between runs) open it with the <tt>Windows-&gt;Python Interactive</tt>
  43. menu entry. </p>
  44. <p>This is the interactive window to the IDE, it allows us to enter
  45. commands directly into Python, and as soon as we enter a command,
  46. Python will execute it and spit its result back to us. We'll be
  47. using this interactive window a lot when we're exploring Python: it's
  48. very nice because we get back our results immediately. If it helps,
  49. we can think of it as a very powerful calculator.</p>
  50. <hr><br style="page-break-after: always">
  51. <p>Let's try something now! As per tradition, let's get Python to say
  52. the immortal words, "Hello World". <img src="hello_world.gif"
  53. border=1 alt="image of hello world program"></p> <p>Those '<tt>&gt;&gt;&gt;</tt>' signs act as a prompt
  54. for us: Python is ready to read in a new command by giving us that
  55. visual cue. Also, we notice that as we enter commands, Python will
  56. give us its output immediately.
  57. </p>
  58. <hr><br style="page-break-after: always">
  59. <p>Ok, this seems pretty simple enough. Let's try a few more
  60. commands. If we look below:</p>
  61. <p><img src="simple_commands.gif" border=1 alt="image of command window"></p>
  62. <p>we'll see the result of running a few more commands. Don't worry
  63. too much about knowing the exact rules for making programs yet: the
  64. idea is that we can experiment with Python by typing in commands. If
  65. things don't work, then we can correct the mistake, and try it
  66. again.</p>
  67. <p>If you got to this point, you now know enough to start playing
  68. around with Python! Crack open one of the tutorials from the <a
  69. href="http://python.org/doc/Newbies.html">Python For Beginners</a> web
  70. page, and start exploring with the interpreter. No time limit here. *grin*</p>
  71. <hr><br style="page-break-after: always">
  72. <p>Now that we've paddled long enough, we might be asking: ok, this is
  73. neat, but if we close down Python and start it up again, how do we get
  74. the computer to remember what we typed?</p>
  75. <p>The solution is a little subtle: we can't directly save what's in
  76. the interpreter window, because it will include both our commands and
  77. the system's responses. What we'd like is to make a prepared file,
  78. with just our own commands, and to be able to save that file as a
  79. document. When we're in the mood, we can later open that file and
  80. "run" Python over it, saving us the time of retyping the whole
  81. thing over again.</p>
  82. <p>Let's try this. First, let's start with a clean slate by opening
  83. up a new window.</p>
  84. <p><img src="making_new_window.gif" border=1 alt="image of making new window"></p>
  85. <p>Here's the result of that menu command:</p>
  86. <p><img src="new_window_made.gif" border=1 alt="image of new window"></p>
  87. <p>We notice that there's nothing in this new window. What this means
  88. is that this file is purely for our commands: Python won't interject
  89. with its own responses as we enter the program, that is, not until we
  90. tell it to. This is called an edit window, and it is very similar
  91. to edit windows in other editors such as TextEdit or BBEdit.</p>
  92. <hr><br style="page-break-after: always">
  93. <p>What we wanted to do before was save some of the stuff we had
  94. tried out on the interpreter window. Let's do that by typing (or
  95. copy/pasting) those commands into our edit window.</p>
  96. <p><img src="entering_in_new_window.gif" border=1 alt="image of entering commands"></p>
  97. <p>Ok, we're done with copying and pasting.
  98. One big thing to notice
  99. is that we're careful to get rid of the "<tt>&gt;&gt;&gt;</tt>"
  100. prompts because they're not really part of our program. The
  101. interpreter uses them just to tell us that we're in the interpreter,
  102. but now that we're editing in a separate file, we can remove the
  103. artifacts that the interpreter introduces.
  104. I have added
  105. an extra empty print statement so our output ends with a newline.
  106. </p>
  107. <hr><br style="page-break-after: always">
  108. <p>Let's save the file now. The Save command is located under the <tt>File</tt> menu:</p>
  109. <p><img src="saving_edited_file.gif" border=1 alt="image of saving file"></p>
  110. <hr><br style="page-break-after: always">
  111. <p>Now that we've saved the program, how do we run the program? Use the
  112. Run All button at the top of the editing window, or the equivalent
  113. menu command <tt>Python-&gt;Run Window</tt>. The output will appear in a new
  114. window called Output Window. </p>
  115. <p>By the way, one thing to notice is that I made a typo: I didn't
  116. quite copy exactly what I had entered in the interpreter window
  117. before. Does this affect things?</p>
  118. <p><img src="syntax_error.gif" border=1 alt="image of syntax error"></p>
  119. <p>Ooops. Here is an example of what Python calls a "syntax error".
  120. Python sees that we made a typo, and warns us to take a much closer
  121. look at our program. The designers of Python feel that having the
  122. system point out the error is better than trying to guess at what the
  123. programmer meant. Press the Edit button and you will be brought to
  124. the trouble spot. </p>
  125. <p>Python is often perceptive enough to direct us toward the problem,
  126. and in this case, it's telling us that we forgot to put something at
  127. the end of this line. In this case, we need to add a
  128. quotation mark at the end. Let's add that in now.</p>
  129. <p>Other errors, which usually occur later, when your program has
  130. already done something, result in a different dialog that allows you
  131. to look at variables and such in addition to showing you where
  132. the error occurred. </p>
  133. <hr><br style="page-break-after: always">
  134. <p>Ok, let's say that we fixed that silly typo. Let's try to run the
  135. program again. This gives us a new window, the Output window, showing
  136. the output of our program:</p>
  137. <p><img src="output_window.gif" border=1 alt="image of output window"></p>
  138. <hr><br style="page-break-after: always">
  139. <p>As we play with Python, we'll find ourselves "switching modes"
  140. between the Interpreter window and the edit window. However,
  141. if we try anything more complicated than two or three lines it
  142. is often a good idea to work in an edit window. Align
  143. your edit and output window such that you can see them at the same time.</p>
  144. <p>This is pretty much all we need to know about the MacPython IDE to actually do
  145. interesting things. There is a lot more to the IDE, here is a quick
  146. breakdown of things to see and explore:</p>
  147. <ul>
  148. <li>All sorts of edit commands such as find and replace can be
  149. used in the editor windows. See the <tt>Edit</tt> menu.</li>
  150. <li>The bottom of the edit window has the scrollbar, but at the
  151. left are two navigation devices: a line number box that you can type
  152. numbers into to quickly go to a specific place, and a popup menu
  153. that lists all classes, functions and methods in your file.</li>
  154. <li>Above the vertical scrollbar you find another popup menu, this
  155. influences how the Run command works. You should try the debugger
  156. some time! If you do, and you wonder what the new small column on
  157. the left of your script is: you can click in it to make Python stop
  158. when it reaches this line so you can inspect things. The profiler
  159. is also nifty: it shows you where your program is spending its time.</li>
  160. <li>The module browser (<tt>Python-&gt;Module Browser</tt>) shows you all Python
  161. modules currently loaded. You can look at the contents of the module with
  162. Browse... and (for modules written in Python) at the source with Source...</li>
  163. <li>The Package Manager (under the <tt>File</tt> menu, also available as a
  164. separate application) allows you to easily install Python extension packages
  165. for all sorts of things: scientific computation, image processing,
  166. building user interfaces and more. </li>
  167. <li>The <tt>Help</tt> menu gives you quick access to both the Python documentation,
  168. if you have installed it with the Package Manager, and the Apple Developer
  169. documentation. </li>
  170. <li>The <tt>File-&gt;Save as Applet</tt> menu command saves your script as a MacOSX
  171. application. This allows you to create a script that you can drop files on,
  172. and much more. The IDE itself is such an applet, completely written in Python. </li>
  173. </ul>
  174. </body>
  175. </html>