Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 1 | <HTML> |
| 2 | <HEAD> |
| 3 | <TITLE>Using Python on the Macintosh</TITLE> |
| 4 | </HEAD> |
| 5 | <BODY> |
| 6 | <H1>Using Python on the Macintosh</H1> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 7 | <HR> |
| 8 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 9 | This document is an introduction to using Python on the Apple |
| 10 | Macintosh. It does not introduce the language itself, for this you |
| 11 | should refer to the <A |
| 12 | HREF="http://www.python.org/doc/tut/tut.html">Python Tutorial</A> by |
| 13 | Guido van Rossum. This guide more-or-less replaces chapter two of the |
| 14 | tutorial, and provides some additional material. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 15 | |
Jack Jansen | 0836542 | 1996-04-19 15:56:08 +0000 | [diff] [blame] | 16 | There is currently no good tutorial for the mac-specific features of |
| 17 | Python, but to whet your appetite: it has interfaces to many MacOS |
| 18 | toolboxes (quickdraw, sound, quicktime, open scripting, etc) and |
| 19 | various portable toolboxes are available too (Tk, stdwin, complex |
| 20 | numbers, image manipulation, etc). Some <A HREF="index.html"> |
| 21 | annotated sample programs</A> are available to give you an idea of |
| 22 | Python's power. <P> |
| 23 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 24 | The document refers to Python 1.3.3 or higher, some of the features |
| 25 | (like setting applet options) will not work in earlier versions of |
| 26 | Python. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 27 | |
| 28 | <h2>Invoking the interpreter</h2> |
| 29 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 30 | The name of the interpreter may differ on different installations: it |
| 31 | may be called <CODE>Python</CODE>, <CODE>PythonPPC</CODE> (for powerpc |
| 32 | macs) or <CODE>Python68K</CODE> (indeed, for 68K macs). It will always |
| 33 | be recognizable by the "16 ton" icon, though. You start the |
Jack Jansen | 0836542 | 1996-04-19 15:56:08 +0000 | [diff] [blame] | 34 | interpreter in interactive mode by double-clicking its icon: <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 35 | |
| 36 | <img src="html.icons/python.gif"><p> |
| 37 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 38 | This should give you a text window with an informative version string |
| 39 | and a prompt, something like the following: |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 40 | <PRE> |
| 41 | Python 1.3.3 (Apr 7 1996) [CW PPC w/GUSI] |
| 42 | Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam |
| 43 | >>> |
| 44 | </PRE> |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 45 | The version string tells you the version of Python, whether it was |
| 46 | built for PPC or 68K macs and possibly some options used to build the |
| 47 | interpreter. If you find a bug or have a question about how the |
| 48 | interpreter works it is a good idea to include the version information |
| 49 | in your message. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 50 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 51 | At the prompt you can type interactive python commands. See the |
| 52 | tutorial for more information. The interactive window works |
| 53 | more-or-less like a Communication Toolbox or Telnet window: you type |
| 54 | commands at the bottom and terminate them with the <EM>[return]</EM> |
| 55 | or <EM>[enter]</EM> key. Interpreter feedback also appears at the |
| 56 | bottom of the window, and the contents scroll as output is added. You |
| 57 | can use copy and paste in the normal way, but be sure to paste only at |
| 58 | the bottom of the document. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 59 | |
| 60 | <h2>Creating Python scripts</h2> |
| 61 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 62 | The Python interpreter works in a way that is different from what you |
| 63 | would expect of a macintosh program: the interpreter is just that: an |
| 64 | interpreter. There is no builtin editor or other development |
| 65 | support. Hence, to create a Python script you need an external text |
| 66 | editor. For a first script you can use any editor that can create |
| 67 | plain, unstyled text files, such as <CODE>SimpleText</CODE>. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 68 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 69 | For more serious scripts, though, it is advisable to use a programmers |
| 70 | editor, such as <CODE>BBEdit</CODE> or <CODE>Alpha</CODE>. BBEdit is |
| 71 | my favorite: it comes in a commercial version but also in a |
| 72 | fully-functional free version <CODE>BBEdit Lite</CODE>. You can |
| 73 | download it from the <A HREF="http://www.barebones.com/">BareBones</A> |
| 74 | site. The free version will probably provide all the functionality |
| 75 | you will ever need. Besides the standard edit facilities it has |
| 76 | multi-file searches and many other goodies that can be very handy when |
| 77 | editing programs. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 78 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 79 | After you have created your script in the editor of your choice you |
| 80 | drop it on the interpreter. This will start the interpreter executing |
| 81 | the script, again with a console window in which the output appears |
| 82 | and in which you can type input if the script requires it. Normally |
| 83 | the interpreter will close the window and quit as soon as the script |
| 84 | is done executing, see below under <A HREF="#startup">startup |
| 85 | options</A> for a way to change this. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 86 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 87 | It is a good idea to have the names of all your scripts end in |
| 88 | <CODE>.py</CODE>. While this is not necessary for standalone scripts |
| 89 | it is needed for modules, and it is probably a good idea to start the |
| 90 | habit now. <p> |
| 91 | |
| 92 | If you do not like to start the Python interpreter afresh for each |
| 93 | edit-run cycle you can use the <CODE>import</CODE> statement and |
| 94 | <CODE>reload()</CODE> function to speed things up in some cases. Here |
| 95 | is Guido's original comment for how to do this, from the 1.1 release |
| 96 | notes: <P> |
| 97 | |
Jack Jansen | 0836542 | 1996-04-19 15:56:08 +0000 | [diff] [blame] | 98 | <BLOCKQUOTE> |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 99 | |
| 100 | Make sure the program is a module file (filename must be a Python |
| 101 | identifier followed by '<CODE>.py</CODE>'). You can then import it |
| 102 | when you test it for the first time. There are now three |
| 103 | possibilities: it contains a syntax error; it gets a runtime error |
| 104 | (unhandled exception); or it runs OK but gives wrong results. (If it |
| 105 | gives correct results, you are done testing and don't need to read the |
| 106 | rest of this paragraph. :-) Note that the following is not |
| 107 | Mac-specific -- it's just that on UNIX it's easier to restart the |
| 108 | entire script so it's rarely useful. <P> |
| 109 | |
| 110 | Recovery from a syntax error is easy: edit the file and import it |
| 111 | again. <P> |
| 112 | |
| 113 | Recovery from wrong output is almost as easy: edit the file and, |
| 114 | instead of importing it, call the function <CODE>reload()</CODE> with |
| 115 | the module name as argument (e.g., if your module is called |
| 116 | <CODE>foo</CODE>, type <CODE>reload(foo)</CODE>). <P> |
| 117 | |
| 118 | Recovery from an exception is trickier. Once the syntax is correct, a |
| 119 | 'module' entry is placed in an internal table, and following import |
| 120 | statements will not re-read the file, even if the module's |
| 121 | initialization terminated with an error (one reason why this is done |
| 122 | is so that mutually recursive modules are initialized only once). You |
| 123 | must therefore force re-reading the module with <CODE>reload()</CODE>, |
| 124 | however, if this happens the first time you try to import the module, |
| 125 | the import statement itself has not completed, and your workspace does |
| 126 | not know the module name (even though the internal table of moduesl |
| 127 | does!). The trick is to first import the module again, then reload |
| 128 | it. For instance, <CODE>import foo; reload(foo)</CODE>. Because the |
| 129 | module object already exists internally, the import statement does not |
| 130 | attempt to execute the module again -- it just places it in your |
Jack Jansen | 0836542 | 1996-04-19 15:56:08 +0000 | [diff] [blame] | 131 | workspace. </BLOCKQUOTE> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 132 | |
| 133 | <h2>Clickable python scripts</h2> |
| 134 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 135 | If you create your script with the correct creator and type, creator |
| 136 | <CODE>'Pyth'</CODE> and type <CODE>'TEXT'</CODE>, you can double-click |
| 137 | your script and it will automatically invoke the interpreter. If you |
| 138 | use BBEdit you can tell it about the Python file type by adding it to |
| 139 | the "file types" sections of the preferences. Then, if you save a file |
| 140 | for the first time you can tell BBEdit to save the file as a Python |
| 141 | script through the "options" choice of the save dialog. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 142 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 143 | The <CODE>Scripts</CODE> folder contains a script |
| 144 | <CODE>fixfiletypes</CODE> that will recursively traverse a folder and |
| 145 | set the correct creator and type for all files ending in |
| 146 | <CODE>.py</CODE>. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 147 | |
Jack Jansen | 0836542 | 1996-04-19 15:56:08 +0000 | [diff] [blame] | 148 | <BLOCKQUOTE> |
| 149 | Older releases of Python used the creator code |
| 150 | <CODE>'PYTH'</CODE> in stead of <CODE>'Pyth'</CODE>. If you still have |
| 151 | older Python sources on your system and named them with |
| 152 | <CODE>'.py'</CODE> extension the <CODE>fixfiletypes</CODE> script will |
| 153 | correct them. |
| 154 | </BLOCKQUOTE> |
| 155 | |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 156 | <h2>Interaction with the user</h2> |
| 157 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 158 | Normally, the interpreter will check for user input (mouse clicks, |
| 159 | keyboard input) every once in a while, so it is possible to switch to |
| 160 | other applications while a script runs. It is also possible to |
| 161 | interrupt the interpreter with the standard command-period keypress, |
| 162 | this will raise the <CODE>KeyboardInterrupt</CODE> exception. Scripts |
| 163 | may, however, turn off this behaviour to facilitate their own event |
| 164 | handling. Such scripts can only be killed with the |
| 165 | command-option-escape shortcut. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 166 | |
| 167 | <h2><A NAME="startup">startup options</A></h2> |
| 168 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 169 | If the <EM>option</EM> key is depressed when Python starts executing |
| 170 | the interpreter will bring up an options dialog thru which you can |
| 171 | influence the way the interpreter behaves. Keep the option key |
| 172 | depressed until the dialog comes up. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 173 | |
| 174 | <img src="html.icons/options.gif"><p> |
| 175 | |
| 176 | The options modify the interpreters behaviour in the following way: |
| 177 | <ul> |
| 178 | <li> the interpreter goes to interactive mode (in stead of |
| 179 | exiting) after a script has terminated normally, |
| 180 | <li> for every module imported a line is printed telling you where the |
| 181 | module was loaded from, |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 182 | <li> do not print the values of expressions executed as statements in |
| 183 | an interactive python, |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 184 | <li> do not buffer stdout and stderr, |
| 185 | <li> print some debugging output during the parsing phase, |
| 186 | <li> keep the output window open when a script terminates. |
| 187 | </ul> |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 188 | In addition, you can enter a unix-style command line which is passed |
| 189 | to the script in <CODE>sys.argv</CODE>. Sys.argv[0] is always the name |
| 190 | of the script being executed, additional values can be passed |
| 191 | here. Quoting works as expected. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 192 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 193 | The default options are also settable on a system-wide basis, see the |
| 194 | section on <A HREF="#preferences">editing preferences</A>. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 195 | |
| 196 | <h2>Module search path</h2> |
| 197 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 198 | The module search path, <CODE>sys.path</CODE>, contains the folders |
| 199 | python will search when you import a module. The path is settable on a |
| 200 | system-wide basis (see the preferences section), and normally |
| 201 | comprises the current folder (where the script lives), the |
| 202 | <CODE>Lib</CODE> folder and some of its subfolders and possibly some |
| 203 | more. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 204 | |
| 205 | <h2>Working folder</h2> |
| 206 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 207 | The unix concept of a <I>working directory</I> does not translate |
| 208 | directly to a similar concept on the Macintosh. To facilitate easy |
| 209 | porting and the use of relative pathnames in scripts the interpreter |
| 210 | simulates a working directory. When a script is started the initial |
| 211 | working directory is the folder where the script lives. In case of an |
| 212 | interactive interpreter the working directory is the folder where the |
| 213 | interpreter lives. <P> |
| 214 | |
| 215 | By the way: the "standard file" folder, the folder that is presented |
| 216 | to the user initially for an <I>open</I> or <I>save</I> dialog, does |
| 217 | <EM>not</EM> follow the Python working directory. Which folder is |
| 218 | initially shown to the user is usually one of (a) the application |
| 219 | folder, (b) the "Documents" folder or (c) the folder most recently |
| 220 | used for such a dialog (in any Python program). This is standard MacOS |
| 221 | behaviour, so don't blame Python for it. The exact behaviour is |
| 222 | settable through a control panel since System 7.5. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 223 | |
| 224 | <h2>Interactive startup file</h2> |
| 225 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 226 | If the folder containing the interpreter contains a file named |
| 227 | <CODE>PythonStartup</CODE> this file is executed when you start an |
| 228 | interactive interpreter. In this file you could import modules you |
| 229 | often use and other such things. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 230 | |
| 231 | |
| 232 | <h2>Compiled python scripts</h2> |
| 233 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 234 | Once a python module has been imported the interpreter creates a |
| 235 | compiled version which is stored in a file with the ".py" extension |
| 236 | replaced by ".pyc". These compiled files, with creator |
| 237 | <CODE>'Pyth'</CODE> and type <CODE>'PYC '</CODE> load faster when |
| 238 | imported (because they do not have to be parsed). The <CODE>Lib</CODE> |
| 239 | folder contains a script <CODE>compileall.py</CODE>, running this |
| 240 | script will cause all modules along the python search path to be |
| 241 | precompiled, which will speed up your programs. Compiled files are |
| 242 | also double-clickable. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 243 | |
| 244 | <h2>Python resources</h2> |
| 245 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 246 | MacPython has the ability to collect a number of compiled modules |
| 247 | together in the resource fork of a single file. This feature is useful |
| 248 | if you distribute a python program and want to minimize clutter: you |
| 249 | can put all the needed modules in a single file (which could even be |
| 250 | the interpreter itself). <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 251 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 252 | If the module search path contains a filename as one of its entries |
| 253 | (as opposed to a folder name, which is the normal case) this file will |
| 254 | be searched for a resource with type <CODE>'PYC '</CODE> and a name |
| 255 | matching the module being imported. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 256 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 257 | The <CODE>scripts</CODE> folder contains a script |
| 258 | <CODE>PackLibDir</CODE> which will convert a number of modules (or |
| 259 | possibly a complete subtree full of modules) into such a resource |
| 260 | file. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 261 | |
| 262 | <h2><A NAME="preferences">Setting interpreter preferences</A></h2> |
| 263 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 264 | The python interpreter keeps a preferences file in the standard |
| 265 | location in the system folder. In this preferences file it remembers |
| 266 | the default module search path and the default settings for the |
| 267 | runtime options. The preferences are settable via |
| 268 | <CODE>EditPythonPrefs</CODE>. For PPC python this is a standalone |
| 269 | program living in the main Python folder, for 68K python it is a |
| 270 | script in the <CODE>Scripts</CODE> folder. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 271 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 272 | The interface to edit the preferences is rather clunky for the current |
| 273 | release. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 274 | |
| 275 | <img src="html.icons/preferences.gif"><p> |
| 276 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 277 | In the editable text field at the top you enter the initial module |
| 278 | search path, using newline as a separator. There are two special |
| 279 | values you can use here: an initial substring <CODE>$(PYTHON)</CODE> |
| 280 | will expand to the Python home folder and a value of |
| 281 | <CODE>$(APPLICATION)</CODE> will expand to the the python application |
| 282 | itself. Note that the text field may extend "beyond the bottom" even |
| 283 | though it does not have a scroll bar. Using the arrow keys works, |
| 284 | though.<p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 285 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 286 | The Python home folder $(PYTHON) is initially, when you execute the |
| 287 | interpreter for the first time, set to the folder where the |
| 288 | interpreter lives. You can change it here. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 289 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 290 | Finally, you can set the default startup options here, through a |
| 291 | sub-dialog. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 292 | |
| 293 | <h2>Applets</h2> |
| 294 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 295 | An applet is a fullblown application written in Python, similar to an |
| 296 | AppleScript applet (and completely different from a Java |
| 297 | applet). Applets are currently only supported on PowerPC macintoshes, |
| 298 | and are created using the <CODE>mkapplet</CODE> program. You create an |
| 299 | applet by dropping the python source script onto mkapplet. The |
| 300 | <CODE>Demo</CODE> folder contains an example of a more involved applet |
| 301 | with its own resource file, etc. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 302 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 303 | Note that while an applet behaves as a fullblown Macintosh application |
| 304 | it is not self-sufficient, so distributing it to a machine without an |
| 305 | installed Python interpreter will not work: it needs the shared python |
| 306 | execution engine <CODE>PythonCore</CODE>, and probably various modules |
| 307 | from the Lib and PlugIns folders. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 308 | |
| 309 | <h2>Customizing applets</h2> |
| 310 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 311 | Applets can have their own settings for the startup options and module |
| 312 | search path. Dropping an applet on the <CODE>EditPythonPrefs</CODE> |
| 313 | application allows you to set these, in the same way as |
| 314 | double-clicking EditPythonPrefs allows you to set the system-wide |
| 315 | defaults. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 316 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 317 | Actually, not only applets but also the interpreter itself can have |
| 318 | non-default settings for path and options. If you make a copy of the |
| 319 | interpreter and drop this copy onto EditPythonPrefs you will have an |
| 320 | interpreter that has a different set of default settings. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 321 | |
| 322 | <h2>Where to go from here</h2> |
| 323 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 324 | The previously mentioned <A |
| 325 | HREF="http://www.python.org/doc/tut/tut.html">Python Tutorial</A> is |
| 326 | an excellent place to start reading if you have never used Python |
| 327 | before. Other documentation such as the library reference manual is |
| 328 | indexed at the <A HREF="http://www.python.org/doc/">Python |
| 329 | Documentation</A> page. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 330 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 331 | There are some <A HREF="index.html">annotated sample programs</A> |
| 332 | available that show some mac-specific issues, like use of various |
| 333 | toolboxes and creation of Python applets. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 334 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 335 | Finally, the <CODE>Demo</CODE> folder in the Macintosh distribution |
| 336 | contains a number of other example programs. Most of these are only |
| 337 | very lightly documented, but they may help you to understand some |
| 338 | aspects of using Python. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 339 | |
| 340 | The best way to contact fellow Macintosh Python programmers is to join |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 341 | the MacPython Special Interest Group mailing list. Send a message with |
| 342 | "info" in the body to <A |
| 343 | HREF="mailto:pythonmac-sig-request@python.org">pythonmac-sig-request@python.org</A> |
| 344 | or view the <A |
| 345 | HREF="http://www.python.org/sigs/pythonmac-sig/">Pythonmac SIG |
| 346 | page</A> on the <A HREF="http://www.python.org">www.python.org</A> WWW |
| 347 | server. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 348 | |
| 349 | <h2>Troubleshooting</h2> |
| 350 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 351 | Python is a rather safe language, and hence it should be difficult to |
| 352 | crash the interpreter of the system with a Python script. There is an |
| 353 | exception to this rule, though: the modules that interface to the |
| 354 | system toolboxes (windowing, quickdraw, etc) do very little error |
| 355 | checking and therefore a misbehaving program using these modules may |
| 356 | indeed crash the system. Such programs are unfortunately rather |
| 357 | difficult to debug, since the crash does not generate the standard |
| 358 | Python stack trace, obviously, and since debugging print statements |
| 359 | will often interfere with the operation of the program. There is |
| 360 | little to do about this currently. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 361 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 362 | Probably the most common cause of problems with modules ported from |
| 363 | other systems is the Mac end-of-line convention. Where unix uses |
Jack Jansen | d9585c9 | 1996-05-07 15:28:20 +0000 | [diff] [blame] | 364 | linefeed, 0x0a, to separate lines the mac uses carriage return, |
| 365 | 0x0d. To complicate matters more a lot of mac programming editors like |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 366 | BBEdit and emacs will work happily with both conventions, so the file |
| 367 | will appear to be correct in the editor but cause strange errors when |
| 368 | imported. BBEdit has a popup menu which allows you to inspect (and |
| 369 | set) the end-of-line convention used in a file. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 370 | |
Jack Jansen | 024a387 | 1996-07-18 16:07:05 +0000 | [diff] [blame^] | 371 | <h2>Where to go from here</h2> |
| 372 | |
| 373 | The next section to check out is the <a href="index.html">annotated sample programs</a>.<p> |
| 374 | |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 375 | <HR> |
| 376 | <A HREF="http://www.cwi.nl/~jack">Jack Jansen</A>, |
Jack Jansen | 0836542 | 1996-04-19 15:56:08 +0000 | [diff] [blame] | 377 | <A HREF="mailto:jack@cwi.nl">jack@cwi.nl</A>, 19-Apr-1996. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 378 | |
| 379 | </BODY> |
| 380 | </HTML> |