This site applies only to CMPT 165 D1 (Burnaby) in Spring 2010. See the CMPT 165 sections page for other sections.
This lab is intended to get you started with Python.
-
Open up IDLE. (In CSIL, select Start → Programs → Python → Python 2.6 → IDLE (Python GUI).) Create an editor window (where you type your programs) by selecting File → New Window. Also see instructions for using Python.
Type (or copy and paste) this code into the editor window. Save it as
first.py.print "I'm a Python program."
print "Outta my way!"Press F5 (or select Run → Run Module) to run the program.
-
Modify
first.pyso it prints this instead:I'm a Python program.
This course is "CMPT 165".In order to print the double quotes in the second line, you will have to use single quotes to enclose the string:
'This course is "CMPT 165".' -
Create a Python program
webtest.pythat prints this (making sure there is a blank line after the first line):Content-type: text/html
<html>
<head>
<title>Web Script</title>
</head>
<body>
<h1>Web Script</h1>
<p>I'm a dynamically generated web page.</p>
</body>
</html>Check your program in IDLE first to make sure it runs and prints text like the above.
Upload this file to your web space on the course web server. Visit the page in your web browser. The URL will be something like this:
http://cmpt165.csil.sfu.ca/~userid/webtest.pyThe server is set up so that Python programs (
.pyfiles) are executed and their output is sent to the browser. (Compare.htmlfiles, where the content of the file is sent as-is.)
When you're done, upload all of the files from this lab to the course web server. The program first.py won't be usable as a web script (since it doesn't print the “Content-type” line).
Make sure the TA has marked you off the grade list before leaving.