Mercurial > cpython-lru_cache-weakref
annotate Doc/mac/using.tex @ 28646:193b8aec00ce legacy-trunk
Changes from Jonathan Riehl to allow his pgen extension (PEP 269) to
work. This includes some more code that used to be part of pgen in
the main parser; I'm okay with that. I'll see if the Windows build
needs work next.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Apr 2003 14:55:42 +0000 |
| parents | 8b49445c0a0e |
| children | fe499bc7381f |
| rev | line source |
|---|---|
|
27833
523efd773261
Updated the Mac documentation to the current state of affairs.
Jack Jansen <jack.jansen@cwi.nl>
parents:
25862
diff
changeset
|
1 \chapter{Using Python on a Mac OS 9 Macintosh \label{using}} |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
2 \sectionauthor{Bob Savage}{bobsavage@mac.com} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
4 Using Python on a Macintosh, especially on Mac OS 9 (MacPython-OSX |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
5 includes a complete unix Python) can seem like something completely |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
6 different than using it on a \UNIX-like or Windows system. Most of the |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
7 Python documentation, both the ``official'' documentation and published |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
8 books, describe only how Python is used on these systems, causing |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
9 confusion for the new user of MacPython-OS9. This chapter gives a brief |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
10 introduction to the specifics of using Python on a Macintosh. |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 |
|
27833
523efd773261
Updated the Mac documentation to the current state of affairs.
Jack Jansen <jack.jansen@cwi.nl>
parents:
25862
diff
changeset
|
13 The section on the IDE (see Section \ref{IDE}) is relevant to MacPython-OSX |
|
523efd773261
Updated the Mac documentation to the current state of affairs.
Jack Jansen <jack.jansen@cwi.nl>
parents:
25862
diff
changeset
|
14 too. |
|
523efd773261
Updated the Mac documentation to the current state of affairs.
Jack Jansen <jack.jansen@cwi.nl>
parents:
25862
diff
changeset
|
15 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
16 \section{Getting and Installing MacPython-OSX \label{getting-OSX}} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
17 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
18 As of Python 2.3a2 the only sure way of getting MacPython-OSX on your machine |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
19 is getting a source distribution and building what is called a "framework Python". |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
20 The details are in the file \file{Mac/OSX/README}. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
21 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
22 As binary installers become available the details will be posted to |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
23 \url{http://www.cwi.nl/\textasciitilde jack/macpython.html}. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
24 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
25 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
26 What you get after installing is a number of things: |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
27 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
28 \begin{itemize} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
29 \item A \file{MacPython-2.3} folder in your \file{Applications} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
30 folder. In here you find the PythonIDE Integrated Development Environment; |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
31 PythonLauncher, which handles double-clicking Python scripts from the Finder; and |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
32 the Package Manager. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
33 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
34 \item A fairly standard unix commandline Python interpreter in |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
35 \file{/usr/local/bin/python}, but without the usual \file{/usr/local/lib/python}. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
36 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
37 \item A framework \file{/Library/Frameworks/Python.framework}, where |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
38 all the action really is, but which you usually do not have to be aware of. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
39 \end{itemize} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
40 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
41 To uninstall MacPython you can simply remove these three things. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
42 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
43 PythonIDE contains an Apple Help Viewer book called "MacPython Help" |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
44 which you can access through its help menu. If you are completely new to |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
45 Python you should start reading the IDE introduction in that document. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
46 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
47 If you are familiar with Python on other unix platforms you should read the |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
48 section on running Python scripts from the unix shell. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
49 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
50 \subsection{How to run a Python script} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
51 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
52 Your best way to get started with Python on Mac OS X is through the PythonIDE |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
53 integrated development environment, see section \ref{IDE} and use the Help |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
54 menu when the IDE is running. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
55 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
56 If you want to run Python scripts from the Terminal window command line |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
57 or from the Finder you first need an editor to create your script. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
58 Mac OS X comes with a number of standard unix command line editors, |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
59 \program{vi} and \program{emacs} among them. If you want a more Mac-like |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
60 editor \program{BBEdit} or \program{TextWrangler} from Bare Bones Software |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
61 (see \url{http://www.barebones.com}) are good choices. Their freeware |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
62 \program{BBEdit Lite} is officially discontinued but still available. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
63 \program{AppleWorks} or any other word processor that can save files |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
64 in ASCII is also a possibility, but \program{TextEdit} is not: it saves in .rtf |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
65 format only. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
66 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
67 To run your script from the Terminal window you must make sure that |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
68 \file{/usr/local/bin} is in your shell search path before \file{/usr/bin}, |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
69 where the Apple-supplied Python lives (which is version 2.2, as of Mac OS X |
|
28578
8b49445c0a0e
Moved all the scripting stuff to a separate section, added all the
Jack Jansen <jack.jansen@cwi.nl>
parents:
28546
diff
changeset
|
70 10.2.4). |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
71 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
72 To run your script from the Finder you have two options: |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
73 \begin{itemize} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
74 \item Drag it to \program{PythonLauncher} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
75 \item Select \program{PythonLauncher} as the default application |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
76 to open your script (or any .py script) through the finder Info window |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
77 and double-click it. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
78 \end{itemize} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
79 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
80 PythonLauncher has various preferences to control how your script is launched. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
81 Option-dragging allows you to change these for one invocation, or use its |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
82 Preferences menu to change things globally. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
83 |
|
28578
8b49445c0a0e
Moved all the scripting stuff to a separate section, added all the
Jack Jansen <jack.jansen@cwi.nl>
parents:
28546
diff
changeset
|
84 \subsection{Running scripts with a GUI \label{osx-gui-scripts}} |
|
8b49445c0a0e
Moved all the scripting stuff to a separate section, added all the
Jack Jansen <jack.jansen@cwi.nl>
parents:
28546
diff
changeset
|
85 |
|
8b49445c0a0e
Moved all the scripting stuff to a separate section, added all the
Jack Jansen <jack.jansen@cwi.nl>
parents:
28546
diff
changeset
|
86 There is one Mac OS X quirk that you need to be aware of: programs |
|
8b49445c0a0e
Moved all the scripting stuff to a separate section, added all the
Jack Jansen <jack.jansen@cwi.nl>
parents:
28546
diff
changeset
|
87 that talk to the Aqua window manager (in other words, anything that has a GUI) |
|
8b49445c0a0e
Moved all the scripting stuff to a separate section, added all the
Jack Jansen <jack.jansen@cwi.nl>
parents:
28546
diff
changeset
|
88 need to be run in a special way. Use \program{pythonw} in stead of \program{python} |
|
8b49445c0a0e
Moved all the scripting stuff to a separate section, added all the
Jack Jansen <jack.jansen@cwi.nl>
parents:
28546
diff
changeset
|
89 to start such scripts. |
|
8b49445c0a0e
Moved all the scripting stuff to a separate section, added all the
Jack Jansen <jack.jansen@cwi.nl>
parents:
28546
diff
changeset
|
90 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
91 \subsection{configuration} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
92 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
93 MacPython honours all standard unix environment variables such as \envvar{PYTHONPATH}, |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
94 but setting these variables for programs started from the Finder is non-standard |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
95 as the Finder does not read your \file{.profile} or \file{.cshrc} at startup. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
96 You need to create a file \file{\textasciitilde /.MacOSX/environment.plist}. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
97 See Apple's Technical Document QA1067 for details. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
98 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
99 Installing additional Python packages is most easily done through the |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
100 Package Manager, see the MacPython Help Book for details. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
101 |
|
27833
523efd773261
Updated the Mac documentation to the current state of affairs.
Jack Jansen <jack.jansen@cwi.nl>
parents:
25862
diff
changeset
|
102 \section{Getting and Installing MacPython-OS9 \label{getting}} |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
103 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
104 The most recent release version as well as possible newer experimental |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
105 versions are best found at the MacPython page maintained by Jack |
| 25862 | 106 Jansen: \url{http://www.cwi.nl/\textasciitilde jack/macpython.html}. |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
107 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
108 Please refer to the \file{README} included with your distribution for |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
109 the most up-to-date instructions. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
110 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
111 Note that MacPython-OS9 runs fine on Mac OS X, and it runs in native |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
112 mode, not in the Classic environment. Unless you have specific |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
113 requirements for a CFM-based Python there is no reason not to |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
114 use MacPython-OSX, though. |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
115 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
116 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
117 \subsection{Entering the interactive Interpreter |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
118 \label{interpreter}} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
119 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
120 The interactive interpreter that you will see used in Python |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
121 documentation is started by double-clicking the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
122 \program{PythonInterpreter} icon, which looks like a 16-ton weight |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
123 falling. You should see the version information and the |
|
17500
5e99a1d0ea4d
Work around the conversion of ">>" and "<<" to guillemets. Reported by Ping.
Fred Drake <fdrake@acm.org>
parents:
15230
diff
changeset
|
124 \samp{>\code{>}>~} prompt. Use it exactly as described in the |
|
5e99a1d0ea4d
Work around the conversion of ">>" and "<<" to guillemets. Reported by Ping.
Fred Drake <fdrake@acm.org>
parents:
15230
diff
changeset
|
125 standard documentation. |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
126 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
127 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
128 \subsection{How to run a Python script} |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
129 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
130 There are several ways to run an existing Python script; two common |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
131 ways to run a Python script are ``drag and drop'' and ``double |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
132 clicking''. Other ways include running it from within the IDE (see |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
133 Section \ref{IDE}), or launching via AppleScript. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
134 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
135 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
136 \subsubsection{Drag and drop} |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
137 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
138 One of the easiest ways to launch a Python script is via ``Drag and |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
139 Drop''. This is just like launching a text file in the Finder by |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
140 ``dragging'' it over your word processor's icon and ``dropping'' it |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
141 there. Make sure that you use an icon referring to the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
142 \program{PythonInterpreter}, not the \program{IDE} or \program{Idle} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
143 icons which have different behaviour which is described below. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
144 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
145 Some things that might have gone wrong: |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
146 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
147 \begin{itemize} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
148 \item |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
149 A window flashes after dropping the script onto the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
150 \program{PythonInterpreter}, but then disappears. Most likely this is a |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
151 configuration issue; your \program{PythonInterpreter} is setup to exit |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
152 immediately upon completion, but your script assumes that if it prints |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
153 something that text will stick around for a while. To fix this, see |
|
15230
10b3cbdbdfd9
Fix some internal references that I botched.
Fred Drake <fdrake@acm.org>
parents:
15229
diff
changeset
|
154 section \ref{defaults}. |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
155 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
156 \item |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
157 When you waved the script icon over the \program{PythonInterpreter}, |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
158 the \program{PythonInterpreter} icon did not hilight. Most likely the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
159 Creator code and document type is unset (or set incorrectly) -- this |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
160 often happens when a file originates on a non-Mac computer. See |
|
15230
10b3cbdbdfd9
Fix some internal references that I botched.
Fred Drake <fdrake@acm.org>
parents:
15229
diff
changeset
|
161 section \ref{creator-code} for more details. |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
162 \end{itemize} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
163 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
164 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
165 \subsubsection{Set Creator and Double Click \label{creator-code}} |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
166 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
167 If the script that you want to launch has the appropriate Creator Code |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
168 and File Type you can simply double-click on the script to launch it. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
169 To be ``double-clickable'' a file needs to be of type \samp{TEXT}, |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
170 with a creator code of \samp{Pyth}. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
171 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
172 Setting the creator code and filetype can be done with the IDE (see |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
173 sections \ref{IDEwrite} and \ref{IDEapplet}), with an editor with a |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
174 Python mode (\program{BBEdit}) -- see section |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
175 \ref{scripting-with-BBedit}, or with assorted other Mac utilities, but |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
176 a script (\file{fixfiletypes.py}) has been included in the MacPython |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
177 distribution, making it possible to set the proper Type and Creator |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
178 Codes with Python. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
179 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
180 The \file{fixfiletypes.py} script will change the file type and |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
181 creator codes for the indicated directory. To use |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
182 \file{fixfiletypes.py}: |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
183 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
184 \begin{enumerate} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
185 \item |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
186 Locate it in the \file{scripts} folder of the \file{Mac} folder of the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
187 MacPython distribution. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
188 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
189 \item |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
190 Put all of the scripts that you want to fix in a folder with nothing |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
191 else in it. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
192 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
193 \item |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
194 Double-click on the \file{fixfiletypes.py} icon. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
195 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
196 \item |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
197 Navigate into the folder of files you want to fix, and press the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
198 ``Select current folder'' button. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
199 \end{enumerate} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
200 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
201 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
202 \subsection{Simulating command line arguments |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
203 \label{argv}} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
204 |
|
27833
523efd773261
Updated the Mac documentation to the current state of affairs.
Jack Jansen <jack.jansen@cwi.nl>
parents:
25862
diff
changeset
|
205 There are two ways to simulate command-line arguments with MacPython-OS9. |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
206 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
207 \begin{enumerate} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
208 \item via Interpreter options |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
209 \begin{itemize} % nestable? I hope so! |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
210 \item Hold the option-key down when launching your script. This will |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
211 bring up a dialog box of Python Interpreter options. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
212 \item Click ``Set \UNIX-style command line..'' button. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
213 \item Type the arguments into the ``Argument'' field. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
214 \item Click ``OK'' |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
215 \item Click ``Run''. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
216 \end{itemize} % end |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
217 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
218 \item via drag and drop |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
219 If you save the script as an applet (see Section \ref{IDEapplet}), you |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
220 can also simulate some command-line arguments via |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
221 ``Drag-and-Drop''. In this case, the names of the files that were |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
222 dropped onto the applet will be appended to \code{sys.argv}, so that |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
223 it will appear to the script as though they had been typed on a |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
224 command line. As on \UNIX\ systems, the first item in \code{sys.srgv} is |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
225 the path to the applet, and the rest are the files dropped on the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
226 applet. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
227 \end{enumerate} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
228 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
229 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
230 \subsection{Creating a Python script} |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
231 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
232 Since Python scripts are simply text files, they can be created in any |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
233 way that text files can be created, but some special tools also exist |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
234 with extra features. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
235 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
236 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
237 \subsubsection{In an editor} |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
238 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
239 You can create a text file with any word processing program such as |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
240 \program{MSWord} or \program{AppleWorks} but you need to make sure |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
241 that the file is saved as ``\ASCII'' or ``plain text''. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
242 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
243 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
244 \subsubsection{Editors with Python modes} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
245 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
246 Several text editors have additional features that add functionality |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
247 when you are creating a Python script. These can include coloring |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
248 Python keywords to make your code easier to read, module browsing, or |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
249 a built-in debugger. These include \program{Alpha}, \program{Pepper}, |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
250 and \program{BBedit}, and the MacPython IDE (Section \ref{IDE}). |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
251 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
252 %\subsubsection{Alpha} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
253 % **NEED INFO HERE** |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
254 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
255 \subsubsection{BBedit \label{scripting-with-BBedit}} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
256 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
257 If you use \program{BBEdit} to create your scripts you will want to tell it about the Python creator code so that |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
258 you can simply double click on the saved file to launch it. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
259 \begin{itemize} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
260 \item Launch \program{BBEdit}. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
261 \item Select ``Preferences'' from the ``Edit'' menu. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
262 \item Select ``File Types'' from the scrolling list. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
263 \item click on the ``Add...'' button and navigate to |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
264 \program{PythonInterpreter} in the main directory of the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
265 MacPython distribution; click ``open''. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
266 \item Click on the ``Save'' button in the Preferences panel. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
267 \end{itemize} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
268 % Are there additional BBedit Python-specific features? I'm not aware of any. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
269 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
270 %\subsubsection{IDE} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
271 %You can use the \program{Python IDE} supplied in the MacPython Distribution to create longer Python scripts |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
272 %-- see Section \ref{IDEwrite} for details. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
273 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
274 %\subsubsection{IDLE} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
275 %Idle is an IDE for Python that was written in Python, using TKInter. You should be able to use it on a Mac by following |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
276 %the standard documentation, but see Section \ref{TKInter} for guidance on using TKInter with MacPython. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
277 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
278 %\subsubsection{Pepper} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
279 % **NEED INFO HERE** |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
280 |
|
28546
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
281 \subsection{Configuration \label{configuration}} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
282 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
283 The MacPython distribution comes with \program{EditPythonPrefs}, an |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
284 applet which will help you to customize the MacPython environment for |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
285 your working habits. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
286 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
287 \subsubsection{EditPythonPrefs\label{EditPythonPrefs}} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
288 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
289 \program{EditPythonPrefs} gives you the capability to configure Python |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
290 to behave the way you want it to. There are two ways to use |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
291 \program{EditPythonPrefs}, you can use it to set the preferences in |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
292 general, or you can drop a particular Python engine onto it to |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
293 customize only that version. The latter can be handy if, for example, |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
294 you want to have a second copy of the \program{PythonInterpreter} that |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
295 keeps the output window open on a normal exit even though you prefer |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
296 to normally not work that way. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
297 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
298 To change the default preferences, simply double-click on |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
299 \program{EditPythonPrefs}. To change the preferences only for one copy |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
300 of the Interpreter, drop the icon for that copy onto |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
301 \program{EditPythonPrefs}. You can also use \program{EditPythonPrefs} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
302 in this fashion to set the preferences of the \program{Python IDE} and |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
303 any applets you create -- see section %s \ref{BuildApplet} and |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
304 \ref{IDEapplet}. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
305 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
306 \subsubsection{Adding modules to the Module Search Path |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
307 \label{search-path}} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
308 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
309 When executing an \keyword{import} statement, Python looks for modules |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
310 in places defined by the \member{sys.path} To edit the |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
311 \member{sys.path} on a Mac, launch \program{EditPythonPrefs}, and |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
312 enter them into the largish field at the top (one per line). |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
313 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
314 Since MacPython defines a main Python directory, the easiest thing is |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
315 to add folders to search within the main Python directory. To add a |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
316 folder of scripts that you created called ``My Folder'' located in the |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
317 main Python Folder, enter \samp{\$(PYTHON):My Folder} onto a new line. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
318 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
319 To add the Desktop under OS 9 or below, add |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
320 \samp{StartupDriveName:Desktop Folder} on a new line. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
321 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
322 \subsubsection{Default startup options \label{defaults}} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
323 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
324 % I'm assuming that there exists some other documentation on the |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
325 % rest of the options so I only go over a couple here. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
326 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
327 The ``Default startup options...'' button in the |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
328 \program{EditPythonPrefs} dialog box gives you many options including |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
329 the ability to keep the ``Output'' window open after the script |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
330 terminates, and the ability to enter interactive mode after the |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
331 termination of the run script. The latter can be very helpful if you |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
332 want to examine the objects that were created during your script. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
333 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
334 %\section{Nifty Tools} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
335 %There are many other tools included with the MacPython |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
336 %distribution. In addition to those discussed here, make |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
337 %sure to check the \file{Mac} directory. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
338 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
339 %\subsection{BuildApplet \label{BuildApplet}} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
340 % **NEED INFO HERE** |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
341 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
342 %\subsection{BuildApplication} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
343 % **NEED INFO HERE** |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
344 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
345 %\section{TKInter on the Mac \label{TKInter}} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
346 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
347 %TKinter is installed by default with the MacPython distribution, but |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
348 %you may need to add the \file{lib-tk} folder to the Python Path (see |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
349 %section \ref{search-path}). Also, it is important that you do not |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
350 %try to launch Tk from within the \program{Python IDE} because the two |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
351 %event loops will collide -- always run a script which uses Tkinter |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
352 %with the \program{PythonInterpreter} instead -- see section |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
353 %\ref{interpreter}. |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
354 |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
355 %\section{CGI on the Mac with Python \label{CGI}} |
|
fd434beb5f56
Created a minimal MacOSX section.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27833
diff
changeset
|
356 %**NEED INFO HERE** |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
357 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
358 \section{The IDE\label{IDE}} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
359 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
360 The \program{Python IDE} (Integrated Development Environment) is a |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
361 separate application that acts as a text editor for your Python code, |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
362 a class browser, a graphical debugger, and more. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
363 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
364 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
365 \subsection{Using the ``Python Interactive'' window} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
366 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
367 Use this window like you would the \program{PythonInterpreter}, except |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
368 that you cannot use the ``Drag and drop'' method above. Instead, |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
369 dropping a script onto the \program{Python IDE} icon will open the |
|
20821
ca418a5fa471
Correct misspelling of "separate" in two places.
Fred Drake <fdrake@acm.org>
parents:
17500
diff
changeset
|
370 file in a separate script window (which you can then execute manually |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
371 -- see section \ref{IDEexecution}). |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
372 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
373 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
374 \subsection{Writing a Python Script \label{IDEwrite}} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
375 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
376 In addition to using the \program{Python IDE} interactively, you can |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
377 also type out a complete Python program, saving it incrementally, and |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
378 execute it or smaller selections of it. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
379 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
380 You can create a new script, open a previously saved script, and save |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
381 your currently open script by selecting the appropriate item in the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
382 ``File'' menu. Dropping a Python script onto the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
383 \program{Python IDE} will open it for editting. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
384 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
385 If you try to open a script with the \program{Python IDE} but either |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
386 can't locate it from the ``Open'' dialog box, or you get an error |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
387 message like ``Can't open file of type ...'' see section |
|
15230
10b3cbdbdfd9
Fix some internal references that I botched.
Fred Drake <fdrake@acm.org>
parents:
15229
diff
changeset
|
388 \ref{creator-code}. |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
389 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
390 When the \program{Python IDE} saves a script, it uses the creator code |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
391 settings which are available by clicking on the small black triangle |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
392 on the top right of the document window, and selecting ``save |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
393 options''. The default is to save the file with the \program{Python |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
394 IDE} as the creator, this means that you can open the file for editing |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
395 by simply double-clicking on its icon. You might want to change this |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
396 behaviour so that it will be opened by the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
397 \program{PythonInterpreter}, and run. To do this simply choose |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
398 ``Python Interpreter'' from the ``save options''. Note that these |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
399 options are associated with the \emph{file} not the application. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
400 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
401 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
402 \subsection{Executing a script from within the IDE |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
403 \label{IDEexecution}} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
404 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
405 You can run the script in the frontmost window of the \program{Python |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
406 IDE} by hitting the run all button. You should be aware, however that |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
407 if you use the Python convention \samp{if __name__ == "__main__":} the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
408 script will \emph{not} be ``__main__'' by default. To get that |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
409 behaviour you must select the ``Run as __main__'' option from the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
410 small black triangle on the top right of the document window. Note |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
411 that this option is associated with the \emph{file} not the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
412 application. It \emph{will} stay active after a save, however; to shut |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
413 this feature off simply select it again. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
414 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
415 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
416 \subsection{``Save as'' versus ``Save as Applet'' |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
417 \label{IDEapplet}} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
418 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
419 When you are done writing your Python script you have the option of |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
420 saving it as an ``applet'' (by selecting ``Save as applet'' from the |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
421 ``File'' menu). This has a significant advantage in that you can drop |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
422 files or folders onto it, to pass them to the applet the way |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
423 command-line users would type them onto the command-line to pass them |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
424 as arguments to the script. However, you should make sure to save the |
|
20821
ca418a5fa471
Correct misspelling of "separate" in two places.
Fred Drake <fdrake@acm.org>
parents:
17500
diff
changeset
|
425 applet as a separate file, do not overwrite the script you are |
|
15229
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
426 writing, because you will not be able to edit it again. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
427 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
428 Accessing the items passed to the applet via ``drag-and-drop'' is done |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
429 using the standard \member{sys.argv} mechanism. See the general |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
430 documentation for more |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
431 % need to link to the appropriate place in non-Mac docs |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
432 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
433 Note that saving a script as an applet will not make it runnable on a |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
434 system without a Python installation. |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
435 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
436 %\subsection{Debugger} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
437 % **NEED INFO HERE** |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
438 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
439 %\subsection{Module Browser} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
440 % **NEED INFO HERE** |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
441 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
442 %\subsection{Profiler} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
443 % **NEED INFO HERE** |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
444 % end IDE |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
445 |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
446 %\subsection{The ``Scripts'' menu} |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
447 % **NEED INFO HERE** |
|
bd88df20da2f
Chapter on how to use MacPython, by Bob Savage <bobsavage@mac.com>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
448 |
