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