-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAB-apple.tex
105 lines (85 loc) · 3.16 KB
/
AB-apple.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
% The contents of this file is
% Copyright (c) 2009- Charles R. Severance, All Righs Reserved
\chapter{Python Programming on Macintosh}
In this appendix, we walk through a series of steps
so you can run Python on Macintosh. Since Python is
already included in the Macintosh Operating system, we need to
learn how to edit Python files and run Python programs
in the terminal window.
There approaches you can take to editing and running
Python programs, and this is just one
approach we have found to be very simple.
First, you need to install a programmer editor. You
do not want to use TextEdit or Microsoft Word to edit
Python programs. Programs must be in "flat-text" files
and so you need an editor that is good at
editing text files.
Our recommended editor for Macintosh is TextWrangler which
can be downloaded and installed from:
\url{http://www.barebones.com/products/TextWrangler/}
To create a Python program, run from
{\bf TextWrangler} from your {\bf Applications} folder.
Lets make our first Python program be:
\beforeverb
\begin{verbatim}
print 'Hello Chuck'
\end{verbatim}
\afterverb
%
Except that you should change it to be your name.
Lets save the file in a folder on your Desktop named
{\tt py4inf}. It is best to keep your folder names short
and not to have any spaces in your folder or file name.
Once you have made the folder, save the file
into {\tt Desktop{\textbackslash}py4inf{\textbackslash}prog1.py}.
The run the {\bf Terminal} program. The easiest way is to
press the Spotlight icon (the magnifying glass) in the upper
right of your screen and enter ``terminal'' and launch the
application that comes up.
You start in your ``home directory''. You can see the current
directory by typing the {\tt pwd} command in the terminal window.
\beforeverb
\begin{verbatim}
67-194-80-15:~ csev$ pwd
/Users/csev
67-194-80-15:~ csev$
\end{verbatim}
\afterverb
%
We must be in the folder that contains your Python program
to run the program. We user the {\tt cd} command to move to a new
folder and then the {\tt ls} command to list the files in the
folder.
\beforeverb
\begin{verbatim}
67-194-80-15:~ csev$ cd Desktop
67-194-80-15:Desktop csev$ cd py4inf
67-194-80-15:py4inf csev$ ls
prog1.py
67-194-80-15:py4inf csev$
\end{verbatim}
\afterverb
%
To run your program, simply type the {\tt python} command followed
by the name of your file at the
command prompt and press enter.
\beforeverb
\begin{verbatim}
67-194-80-15:py4inf csev$ python prog1.py
Hello Chuck
67-194-80-15:py4inf csev$
\end{verbatim}
\afterverb
%
You can edit the file in TextWrangler, save it and then switch back
to the command line and execute the program again by typing
the file name again at the command line prompt.
If you get confused in the command line window - just close it
and start a new one.
Hint: You can also press the ``up-arrow'' in the command line to
scroll back and run a previously entered command again.
You should also look in the preferences for TextWrangler and set it
to expand tab characters to be four spaces. It will save you lots
of effort looking for indentation errors.
You can also find further information on editing and running
Python programs at \url{www.py4inf.com}.