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 | 22fa642 | 1996-09-05 15:15:59 +0000 | [diff] [blame^] | 193 | <BLOCKQUOTE> |
| 194 | <EM>Warning:</EM> redirecting standard input or standard output in the |
| 195 | command-line dialog does not work. This is due to circumstances beyond my |
| 196 | control, hence I cannot say when this will be fixed. |
| 197 | </BLOCKQUOTE> |
| 198 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 199 | The default options are also settable on a system-wide basis, see the |
| 200 | section on <A HREF="#preferences">editing preferences</A>. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 201 | |
| 202 | <h2>Module search path</h2> |
| 203 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 204 | The module search path, <CODE>sys.path</CODE>, contains the folders |
| 205 | python will search when you import a module. The path is settable on a |
| 206 | system-wide basis (see the preferences section), and normally |
| 207 | comprises the current folder (where the script lives), the |
| 208 | <CODE>Lib</CODE> folder and some of its subfolders and possibly some |
| 209 | more. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 210 | |
| 211 | <h2>Working folder</h2> |
| 212 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 213 | The unix concept of a <I>working directory</I> does not translate |
| 214 | directly to a similar concept on the Macintosh. To facilitate easy |
| 215 | porting and the use of relative pathnames in scripts the interpreter |
| 216 | simulates a working directory. When a script is started the initial |
| 217 | working directory is the folder where the script lives. In case of an |
| 218 | interactive interpreter the working directory is the folder where the |
| 219 | interpreter lives. <P> |
| 220 | |
| 221 | By the way: the "standard file" folder, the folder that is presented |
| 222 | to the user initially for an <I>open</I> or <I>save</I> dialog, does |
| 223 | <EM>not</EM> follow the Python working directory. Which folder is |
| 224 | initially shown to the user is usually one of (a) the application |
| 225 | folder, (b) the "Documents" folder or (c) the folder most recently |
| 226 | used for such a dialog (in any Python program). This is standard MacOS |
| 227 | behaviour, so don't blame Python for it. The exact behaviour is |
| 228 | settable through a control panel since System 7.5. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 229 | |
| 230 | <h2>Interactive startup file</h2> |
| 231 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 232 | If the folder containing the interpreter contains a file named |
| 233 | <CODE>PythonStartup</CODE> this file is executed when you start an |
| 234 | interactive interpreter. In this file you could import modules you |
| 235 | often use and other such things. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 236 | |
| 237 | |
| 238 | <h2>Compiled python scripts</h2> |
| 239 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 240 | Once a python module has been imported the interpreter creates a |
| 241 | compiled version which is stored in a file with the ".py" extension |
| 242 | replaced by ".pyc". These compiled files, with creator |
| 243 | <CODE>'Pyth'</CODE> and type <CODE>'PYC '</CODE> load faster when |
| 244 | imported (because they do not have to be parsed). The <CODE>Lib</CODE> |
| 245 | folder contains a script <CODE>compileall.py</CODE>, running this |
| 246 | script will cause all modules along the python search path to be |
| 247 | precompiled, which will speed up your programs. Compiled files are |
| 248 | also double-clickable. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 249 | |
| 250 | <h2>Python resources</h2> |
| 251 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 252 | MacPython has the ability to collect a number of compiled modules |
| 253 | together in the resource fork of a single file. This feature is useful |
| 254 | if you distribute a python program and want to minimize clutter: you |
| 255 | can put all the needed modules in a single file (which could even be |
| 256 | the interpreter itself). <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 257 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 258 | If the module search path contains a filename as one of its entries |
| 259 | (as opposed to a folder name, which is the normal case) this file will |
| 260 | be searched for a resource with type <CODE>'PYC '</CODE> and a name |
| 261 | matching the module being imported. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 262 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 263 | The <CODE>scripts</CODE> folder contains a script |
| 264 | <CODE>PackLibDir</CODE> which will convert a number of modules (or |
| 265 | possibly a complete subtree full of modules) into such a resource |
| 266 | file. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 267 | |
| 268 | <h2><A NAME="preferences">Setting interpreter preferences</A></h2> |
| 269 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 270 | The python interpreter keeps a preferences file in the standard |
| 271 | location in the system folder. In this preferences file it remembers |
| 272 | the default module search path and the default settings for the |
| 273 | runtime options. The preferences are settable via |
| 274 | <CODE>EditPythonPrefs</CODE>. For PPC python this is a standalone |
| 275 | program living in the main Python folder, for 68K python it is a |
| 276 | script in the <CODE>Scripts</CODE> folder. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 277 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 278 | The interface to edit the preferences is rather clunky for the current |
| 279 | release. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 280 | |
| 281 | <img src="html.icons/preferences.gif"><p> |
| 282 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 283 | In the editable text field at the top you enter the initial module |
| 284 | search path, using newline as a separator. There are two special |
| 285 | values you can use here: an initial substring <CODE>$(PYTHON)</CODE> |
| 286 | will expand to the Python home folder and a value of |
| 287 | <CODE>$(APPLICATION)</CODE> will expand to the the python application |
| 288 | itself. Note that the text field may extend "beyond the bottom" even |
| 289 | though it does not have a scroll bar. Using the arrow keys works, |
| 290 | though.<p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 291 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 292 | The Python home folder $(PYTHON) is initially, when you execute the |
| 293 | interpreter for the first time, set to the folder where the |
| 294 | interpreter lives. You can change it here. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 295 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 296 | Finally, you can set the default startup options here, through a |
| 297 | sub-dialog. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 298 | |
| 299 | <h2>Applets</h2> |
| 300 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 301 | An applet is a fullblown application written in Python, similar to an |
| 302 | AppleScript applet (and completely different from a Java |
| 303 | applet). Applets are currently only supported on PowerPC macintoshes, |
| 304 | and are created using the <CODE>mkapplet</CODE> program. You create an |
| 305 | applet by dropping the python source script onto mkapplet. The |
| 306 | <CODE>Demo</CODE> folder contains an example of a more involved applet |
| 307 | with its own resource file, etc. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 308 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 309 | Note that while an applet behaves as a fullblown Macintosh application |
| 310 | it is not self-sufficient, so distributing it to a machine without an |
| 311 | installed Python interpreter will not work: it needs the shared python |
| 312 | execution engine <CODE>PythonCore</CODE>, and probably various modules |
| 313 | from the Lib and PlugIns folders. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 314 | |
| 315 | <h2>Customizing applets</h2> |
| 316 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 317 | Applets can have their own settings for the startup options and module |
| 318 | search path. Dropping an applet on the <CODE>EditPythonPrefs</CODE> |
| 319 | application allows you to set these, in the same way as |
| 320 | double-clicking EditPythonPrefs allows you to set the system-wide |
| 321 | defaults. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 322 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 323 | Actually, not only applets but also the interpreter itself can have |
| 324 | non-default settings for path and options. If you make a copy of the |
| 325 | interpreter and drop this copy onto EditPythonPrefs you will have an |
| 326 | interpreter that has a different set of default settings. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 327 | |
| 328 | <h2>Where to go from here</h2> |
| 329 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 330 | The previously mentioned <A |
| 331 | HREF="http://www.python.org/doc/tut/tut.html">Python Tutorial</A> is |
| 332 | an excellent place to start reading if you have never used Python |
| 333 | before. Other documentation such as the library reference manual is |
| 334 | indexed at the <A HREF="http://www.python.org/doc/">Python |
| 335 | Documentation</A> page. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 336 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 337 | There are some <A HREF="index.html">annotated sample programs</A> |
| 338 | available that show some mac-specific issues, like use of various |
| 339 | toolboxes and creation of Python applets. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 340 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 341 | Finally, the <CODE>Demo</CODE> folder in the Macintosh distribution |
| 342 | contains a number of other example programs. Most of these are only |
| 343 | very lightly documented, but they may help you to understand some |
| 344 | aspects of using Python. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 345 | |
| 346 | The best way to contact fellow Macintosh Python programmers is to join |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 347 | the MacPython Special Interest Group mailing list. Send a message with |
| 348 | "info" in the body to <A |
| 349 | HREF="mailto:pythonmac-sig-request@python.org">pythonmac-sig-request@python.org</A> |
| 350 | or view the <A |
| 351 | HREF="http://www.python.org/sigs/pythonmac-sig/">Pythonmac SIG |
| 352 | page</A> on the <A HREF="http://www.python.org">www.python.org</A> WWW |
| 353 | server. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 354 | |
| 355 | <h2>Troubleshooting</h2> |
| 356 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 357 | Python is a rather safe language, and hence it should be difficult to |
| 358 | crash the interpreter of the system with a Python script. There is an |
| 359 | exception to this rule, though: the modules that interface to the |
| 360 | system toolboxes (windowing, quickdraw, etc) do very little error |
| 361 | checking and therefore a misbehaving program using these modules may |
| 362 | indeed crash the system. Such programs are unfortunately rather |
| 363 | difficult to debug, since the crash does not generate the standard |
| 364 | Python stack trace, obviously, and since debugging print statements |
| 365 | will often interfere with the operation of the program. There is |
| 366 | little to do about this currently. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 367 | |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 368 | Probably the most common cause of problems with modules ported from |
| 369 | other systems is the Mac end-of-line convention. Where unix uses |
Jack Jansen | d9585c9 | 1996-05-07 15:28:20 +0000 | [diff] [blame] | 370 | linefeed, 0x0a, to separate lines the mac uses carriage return, |
| 371 | 0x0d. To complicate matters more a lot of mac programming editors like |
Jack Jansen | bd9565a | 1996-04-15 12:25:44 +0000 | [diff] [blame] | 372 | BBEdit and emacs will work happily with both conventions, so the file |
| 373 | will appear to be correct in the editor but cause strange errors when |
| 374 | imported. BBEdit has a popup menu which allows you to inspect (and |
| 375 | set) the end-of-line convention used in a file. <p> |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 376 | |
Jack Jansen | 024a387 | 1996-07-18 16:07:05 +0000 | [diff] [blame] | 377 | <h2>Where to go from here</h2> |
| 378 | |
| 379 | The next section to check out is the <a href="index.html">annotated sample programs</a>.<p> |
| 380 | |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 381 | <HR> |
| 382 | <A HREF="http://www.cwi.nl/~jack">Jack Jansen</A>, |
Jack Jansen | 22fa642 | 1996-09-05 15:15:59 +0000 | [diff] [blame^] | 383 | <A HREF="mailto:jack@cwi.nl">jack@cwi.nl</A>, 05-Sep-1996. |
Jack Jansen | 5f962c2 | 1996-04-10 14:52:59 +0000 | [diff] [blame] | 384 | |
| 385 | </BODY> |
| 386 | </HTML> |