forked from csev/py4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfbook018.html
More file actions
109 lines (109 loc) · 4.43 KB
/
cfbook018.html
File metadata and controls
109 lines (109 loc) · 4.43 KB
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
104
105
106
107
108
109
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="GENERATOR" content="hevea 1.07" />
<title>
Python Programming on Windows
</title>
</head>
<body>
<a href="cfbook017.html"><img src="previous_motif.gif" alt="Previous" /></a>
<a href="index.html"><img src="contents_motif.gif" alt="Up" /></a>
<a href="cfbook019.html"><img src="next_motif.gif" alt="Next" /></a>
<hr />
<h1><font color="black"><a name="htoc196">Appendix A</a> Python Programming on Windows</font></h1>
<font color="black">In this appendix, we walk through a series of steps
so you can run Python on Windows. There are many different
approaches you can take, and this is just one
approach to keep things simple.<br />
<br />
First, you need to install a programmer editor. You
do not want to use Notepad 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.<br />
<br />
Our recommended editor for Windows is NotePad++ which
can be downloaded and installed from:<br />
<br />
<tt>http://sourceforge.net/projects/notepad-plus/files/</tt><br />
<br />
Then download a recent version of Python 2 from the
<tt>www.python.org</tt> web site.<br />
<br />
<tt>http://www.python.org/download/releases/2.7.5/</tt><br />
<br />
Once you have installed Python, you should have a new
folder on your computer like <tt>C:\Python27</tt>.<br />
<br />
To create a Python program, run NotePad++ from the Start Menu
and save the file with a suffix of ".py". For this
exercise, put a folder on your Desktop named
<tt>py4inf</tt>. It is best to keep your folder names short
and not to have any spaces in your folder or file name.<br />
<br />
Lets make our first Python program be:
</font><pre><font size="4" color="blue">
print 'Hello Chuck'
</font></pre><font color="black">Except that you should change it to be your name. Lets
save the file into <tt>Desktop\py4inf\prog1.py</tt>.<br />
<br />
The run the command line. Different versions of Windows
do this differently:
</font><ul><li>
<font color="black">Windows Vista and Windows-7: Press <b>Start</b>
and then in the command search window enter the word
<tt>command</tt> and press enter.</font><br />
<br />
</li><li><font color="black">Windows-XP: Press <b>Start</b>, then <b>Run</b>, and
then enter <tt>cmd</tt> in the dialog box and press <b>OK</b>.
</font></li></ul>
<font color="black">You will find yourself in a text window with a prompt that
tells you what folder you are currently "in". <br />
<br />
Windows Vista and Windows-7: <tt>C:\Users\csev</tt><br />
Windows XP: <tt>C:\Documents and Settings\csev</tt><br />
<br />
This is your "home directory". Now we need to move into
the folder where you have saved your Python program using
the following commands:
</font><pre><font size="4" color="blue">
C:\Users\csev\> cd Desktop
C:\Users\csev\Desktop> cd py4inf
</font></pre><font color="black">Then type
</font><pre><font size="4" color="blue">
C:\Users\csev\Desktop\py4inf> dir
</font></pre><font color="black">To list your files. You should see the <tt>prog1.py</tt> when
you type the <tt>dir</tt> command.<br />
<br />
To run your program, simply type the name of your file at the
command prompt and press enter.
</font><pre><font size="4" color="blue">
C:\Users\csev\Desktop\py4inf> prog1.py
Hello Chuck
C:\Users\csev\Desktop\py4inf>
</font></pre><font color="black">You can edit the file in NotePad++, 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.<br />
<br />
If you get confused in the command line window - just close it
and start a new one.<br />
<br />
Hint: You can also press the "up-arrow" in the command line to
scroll back and run a previously entered command again.<br />
<br />
You should also look in the preferences for NotePad++ and set it
to expand tab characters to be four spaces. It will save you lots
of effort looking for indentation errors.<br />
<br />
You can also find further information on editing and running
Python programs at <tt>www.py4inf.com</tt>.</font><br />
<br />
<hr />
<a href="cfbook017.html"><img src="previous_motif.gif" alt="Previous" /></a>
<a href="index.html"><img src="contents_motif.gif" alt="Up" /></a>
<a href="cfbook019.html"><img src="next_motif.gif" alt="Next" /></a>
</body>
</html>