annotate Mac/Demo/using.html @ 4566:6403c94de50d legacy-trunk

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