forked from csev/py4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook018.html
More file actions
62 lines (62 loc) · 5.08 KB
/
book018.html
File metadata and controls
62 lines (62 loc) · 5.08 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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="hevea 2.09" />
<link rel="stylesheet" type="text/css" href="book.css" />
<title>Python Programming on Windows</title>
</head>
<body>
<a href="book017.html"><img src="previous_motif.gif" alt="Previous" /></a>
<a href="index.html"><img src="contents_motif.gif" alt="Up" /></a>
<a href="book019.html"><img src="next_motif.gif" alt="Next" /></a>
<hr />
<h1 class="chapter" id="sec197"><span class="c006">Appendix A  Python Programming on Windows</span></h1>
<p><span class="c006">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.</span></p><p><span class="c006">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.</span></p><p><span class="c006">Our recommended editor for Windows is NotePad++ which
can be downloaded and installed from:</span></p><p><span class="c002">http://sourceforge.net/projects/notepad-plus/files/</span></p><p><span class="c006">Then download a recent version of Python 2 from the
<span class="c001">www.python.org</span> web site.</span></p><p><span class="c002">http://www.python.org/download/releases/2.7.5/</span></p><p><span class="c006">Once you have installed Python, you should have a new
folder on your computer like <span class="c001">C:\Python27</span>.</span></p><p><span class="c006">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
<span class="c001">py4inf</span>. It is best to keep your folder names short
and not to have any spaces in your folder or file name.</span></p><p><span class="c006">Lets make our first Python program be:</span></p><pre class="verbatim"><span class="c004">print 'Hello Chuck'
</span></pre><p><span class="c006">Except that you should change it to be your name. Lets
save the file into <span class="c001">Desktop\py4inf\prog1.py</span>.</span></p><p><span class="c006">The run the command line. Different versions of Windows
do this differently:</span></p><ul class="itemize"><li class="li-itemize"><span class="c006">
Windows Vista and Windows-7: Press <span class="c009">Start</span>
and then in the command search window enter the word
<span class="c001">command</span> and press enter.</span></li><li class="li-itemize"><span class="c006">Windows-XP: Press <span class="c009">Start</span>, then <span class="c009">Run</span>, and
then enter <span class="c001">cmd</span> in the dialog box and press <span class="c009">OK</span>.
</span></li></ul><p><span class="c006">You will find yourself in a text window with a prompt that
tells you what folder you are currently “in”. </span></p><p><span class="c006">Windows Vista and Windows-7: <span class="c001">C:\Users\csev</span><br />
Windows XP: <span class="c001">C:\Documents and Settings\csev</span></span></p><p><span class="c006">This is your “home directory”. Now we need to move into
the folder where you have saved your Python program using
the following commands:</span></p><pre class="verbatim"><span class="c004">C:\Users\csev\> cd Desktop
C:\Users\csev\Desktop> cd py4inf
</span></pre><p><span class="c006">Then type </span></p><pre class="verbatim"><span class="c004">C:\Users\csev\Desktop\py4inf> dir
</span></pre><p><span class="c006">To list your files. You should see the <span class="c001">prog1.py</span> when
you type the <span class="c001">dir</span> command.</span></p><p><span class="c006">To run your program, simply type the name of your file at the
command prompt and press enter.</span></p><pre class="verbatim"><span class="c004">C:\Users\csev\Desktop\py4inf> prog1.py
Hello Chuck
C:\Users\csev\Desktop\py4inf>
</span></pre><p><span class="c006">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.</span></p><p><span class="c006">If you get confused in the command line window - just close it
and start a new one.</span></p><p><span class="c006">Hint: You can also press the “up-arrow” in the command line to
scroll back and run a previously entered command again.</span></p><p><span class="c006">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.</span></p><p><span class="c006">You can also find further information on editing and running
Python programs at <span class="c001">www.py4inf.com</span>.</span></p><span class="c005">
</span><hr />
<a href="book017.html"><img src="previous_motif.gif" alt="Previous" /></a>
<a href="index.html"><img src="contents_motif.gif" alt="Up" /></a>
<a href="book019.html"><img src="next_motif.gif" alt="Next" /></a>
</body>
</html>