Introduction to Python (Jan-Feb 2011)

Welcome!

Day 1 (January 17th)

Day 2 (January 24th)

Day 3 (January 31st)

Day 4 (February 7th)

Day 5 (February 14th)

Day 6 (February 21st)


These courses notes are licensed under the CC-BY-NC license.

Note: If you're only looking for exercises for your own courses, don't worry about the license and just grab them. Please feel very free to share back in exchange any exercise or resources you found useful elsewhere -- I always struggle to find more! Add a comment or contact me directly.


Monday, January 17th

Please try to install Python and the programming environment following the next 2 steps before Monday, so we can start on the interesting parts as soon as possible (also, note that there likely won't be Internet access during the class -- downloading these in advance will certainly be useful!). If you get stuck, no worries, we will sort it out on the day.

Installing Python

We're going to be working with Python 2. If you have any Python version > 2.5, you're fine.

  • Linux: Already installed (Type "python --version" into a command line if you're curious to know which version you're using)
  • Mac: Python should already be installed with Mac OS X.
  • Windows: Download Python from the official website.

Windows note: Make sure to update your PATH environment variable with your Python path. (My Computer -> Properties -> Advanced -> Environment Variables. Find the variable named "PATH" and at the end, add the path where Python installed -- I think it should be something like c:\python27\).

Installing the programming environment

To simplify programming, I'd like us to use an IDE (Integrated Development Environment).

  • Linux

Option 1 (Recommended): Please install Geany, it should be in your repositories (look in Synaptic, for Ubuntu).

Option 2: IDLE, which is installable from the repositories as well.

  • Windows

Option 1 (Recommended): Please download and install Geany.

Option 2: Use IDLE, installed by default with Python (somewhere like c:\python27\idlelib\idle.pyw)

  • Mac

Unfortunately, I don't believe it's possible to run Geany on a Mac. We will be using IDLE, which I'm not sure whether it's installed by default... Just in case and if you can't find IDLE on your machine, please download and install the Python executable, it will be included.

Note: If you're running Mac OS X 10.6 there might be an issue where IDLE crashes a lot. Have a look here and download the latest version of Tcl/Th for your machine to resolve it.

Note: I don't have access to a Mac, which limits my ways of testing an IDE. If anyone has Xcode installed (requires free registration), or has the time and inclination to download and install it before we meet, I would love to have a quick look and check if it's appropriate for the course. Get in touch!

A taste of Python

A Python file must end with .py and the name must be all lowercase. No spaces.

e.g. example.py

Displaying text on screen

print "Hello, world!"

Variables

The symbol = means assigning the value on the right, to the variable as named on the left.

name = "Bob"
print "Hello", name

Variable types

Double-quotes around a text means it's a piece of text, also called string. Numbers are usually called integer. Try this:

print 2 + 2
print "2" + "2"

You can force a variable or a piece of text to be treated as a number, rather than as text, by using the function int():

print int("2") + int("2")

Getting user input

name = raw_input("What's your name? ")
print "Hello", name

Note that raw_input() will always return a text value. If you're expecting a number you will have to convert it using int().

Comment

# This is a comment,it is meant for humans and will not be interpreted by Python
# Every comment line must begin with a #
print "Hi!" # You can write a comment after a programming instruction

If condition

Be mindful of:

  • the indentation, and make sure to keep it consistent
  • the colon at the end of the "if" statement and after the "else"
number = raw_input("Please enter a number: ")

if int(number) > 5:
    print "Number is higher than 5."
else:
    print "Number if 5 or lower."

print "This text will be displayed all the time, because there is no indentation."

Comparison operators

>    Greater than
>=   Greater than or equal to
<    Less than
<=   Less than or equal to
==   Equal
!=   Not equal

Exercises

5 exercises, of 3 types:

- Adapt the behaviour of an existing working program, so that it does something else as per the instructions (1 exercise: A)

- Fill in the blanks (1 exercise: B)

- Write this program from scratch (3 exercises: C, D, E)

# # #

A. 

This program works:

rate = int(raw_input("Please enter the rate (%): "))

if rate < 50:
    print "Mediocre"
elif rate < 80:
    print "Ok"
elif rate <= 100:
    print "Great!"

1. Change this program so that a rate under 5 writes "Boo!" on the screen.

2. Change this program so that everything between 15 and 80 is "Ok".

3. Change this program so that "100" prints "Perfect!"

# # #

B.

Fill in the blanks so that this program works correctly:

age = raw_input(.................)
country = ............("What is your country? ")

if country ....   ..............:
    if int(age) >= 18:
        print "You can vote"
    else:
        print "You cannot vote"

if country == "Fiji":
    if int(age) < 21:
        print .................
    else:
        print .................

if country != "Ireland" and country != "Fiji":
    print "I don't know"

Notes:

  • You can vote from 18 in Ireland
  • You can vote from 21 in Fiji

# # #

C.

Ask the user for a user name and a password. If the user types the correct combination, display "Welcome!" otherwise display "Wrong user name or password."

Example program output (bold is data entered by the user):
Username? no one
Password? passw0rd
Wrong user name or password.

Example program output (bold is data entered by the user):
Username? Ulysse
Password? passw0rd
Welcome!

D.

Write a text user interface similar to the following, that shows a menu with a few options to the user. When the user types in "a", "b", or "c", a different response is displayed on the screen.

 _____________________________________
|                                     | 
|         HELLO!                      | 
|       /                             | 
|    \O         Choose an             | 
|     |\             option           | 
|    / \                              | 
|                                     | 
|              a. Say hi              | 
|              b. Say goodbye         | 
|              c. Fortune cookie      | 
|_____________________________________| 

E.

Write a program to find out whether a year is a leap year. A year is a leap year if it is divisible by 4, but not by 100 unless it can be divided by 400 as well.

For example: 

  • 1992, 1996, 2000, are leap years.
  • 1993, 1900, 2010 are not leap years.

Example program output (bold is data entered by the user):
What year? 1996
1996 is a leap year.

Tips:

  • To have several conditions in an if statement, you can use the word "and" (see exercise B for an example).
  • To get the remainder of a division, you should use the operator %. It's called "modulo" and has nothing to do with percentages (just to be confusing!). An example of how it's used:
print 5 / 3    # prints "1" on screen. 5 divided by 3, result is 1
print 5 % 3    # prints "2" on screen. 5 divided by 3, remainder is 2

Sample answer (E)

year = int(raw_input("What year? "))

if year % 4 == 0 and (not year % 100 == 0 or (year % 100 == 0 and year % 400 == 0)):
    print year, "is a leap year."
else:
    print year, "is not a leap year."

Monday, January 24th

While loop: "Guess the number" game

import random 

solution = random.randint(1, 10) # Random integer between 1 and 10
max_guess = 5
 
number = raw_input("Guess the number: ")
guess = 1

while int(number) != solution and guess < max_guess:      guess = guess + 1      if int(number) < solution:          print "Wrong guess (too low). Please try again."      else:          print "Wrong guess (too high). Please try again"      number = raw_input("Guess the number: ") if int(number) == solution:     print "Congratulations! You guessed the number right." else:     print "You've reached the maximum number of guesses. The number was", solution
  • "While" kind of works like "If". It's followed by a condition, it can contain and/or and the content is marked by indentation. The loop keeps execution while the condition is true. The body of the loop is skipped if/when the condition becomes false.
  • Beware the infinite loop!
  • "random" is a Python library containing various functions. To see what other interesting functions it contains, go to http://docs.python.org/ -> Global Module Index -> R -> random.

While: Exercises

A*.

Ask the user for a number, until the user enters 0. Then add all the numbers and display the total.

Example program output (user input is in bold):
Enter a number (0 to end): 5
Enter a number (0 to end): 1
Enter a number (0 to end): 14
Enter a number (0 to end): 0 
Total is: 20

B.

Ask the user for a user name and password. This time, the user gets 3 attempts in case if they get it wrong.

Example program output (user input is in bold):
Username? me
Password? hello
Wrong user name or password. Please try again.
Username?
...(etc)...

Optionally: Tell the user how many attempts they have left. Hint: Use str(variable_name) to concatenate string and number, for example: 

print "My favourite number is " + str(my_number)

C*.

Ask the user how many values they want to enter. Then get the number of values asked for and display the average.

Example program output (user input is in bold):
How many values to enter? 3
Enter value: 98
Enter value: 52
Enter value: 27
Average is: 59

D.

Remember this?

 _____________________________________
|                                     | 
|         HELLO!                      | 
|       /                             | 
|    \O         Choose an             | 
|     |\             option           | 
|    / \                              | 
|                                     | 
|              a. Say hi              | 
|              b. Say goodbye         | 
|              c. Fortune cookie      | 
|_____________________________________| 

Add  a fourth option: "q. Quit" and change the program so that the user can keep choosing an option, until they choose option "q" and the program exits.

Sample answer (A)

total = 0

number = raw_input("Enter a number (0 to end): ")

while int(number) != 0:
    total += int(number)
    number = raw_input("Enter a number (0 to end): ")

print "Total is:", total

Break: Code reading

What does this do?

count = -1

while count <= 0:
    count = int(raw_input("What's the countdown? "))

while count > 0:
    print count
    count = count - 1

print
print "TADAM!"

Data structure: Lists/Arrays

restaurants = ["McDonald's", "KFC", "Chapter One", "Mona Lisa"]
adjectives = ["great", "awesome", "bad", "yucky"]
  • A new type of variable to store multiple values
  • Note the square brackets
  • The "address" of an element is called its index, it starts from 0.

For loop

for i in range(0, 4):
    print restaurants[i], "are", adjectives[i]
    
print

for i in range(0, len(restaurants)):
    print restaurants[i], "are", adjectives[i]

print

for r in restaurants:
    print r
  • More convenient to go through a list
  • i is the common short name for "index"
  • len() returns the length of a list
  • range(start, end): the "start" number is inclusive, the "end" number is exclusive. range(0, 4) returns the following list of numbers: [0, 1, 2, 3]

For: Exercises

*.

Redo the first set of exercises with a *, this time using a "for" loop to solve the problem.

E.

You have a list of numbers. Print the largest number from the list. Extra: Make sure it also works when the list only contains negative numbers.

Example program output:
List is: 0, 7, 9, 15, 8
Largest number is 15

Example program output:
List is: -15, -2, -4, -9
Largest number is -2

F.

Print the multiplication tables from 2 to 10, using two 'for' loops. (Note: Your final program shouldn't be any longer than 5 or 6 lines!)

Hint: If you're not sure where to start, start by writing the multiplication table for only one number, say 5, using one 'for' loop.

G.

Ask the user for a number between 1 and 12. Print the month associated with the number.If the user enters an incorrect number (0, 13, 24, ...), display an error message.

Example program output (user input is in bold):
Please enter a number between 1 and 12: 9
Month is: September

H.

Ask the user for a sentence. Count the number of words in the sentence.

Example program output (user input is in bold):
Enter a sentence: Ask the user for a sentence. Count the number of words in the sentence.
Number of words:  14 

Sample answer (E)

numbers = [0, 7, 9, 15, 8]
largest = numbers[0]

for number in numbers:
    if number > largest:
        largest = number

print "Largest is:", largest

Sample answer (F)

for i in range(2, 10):
    for j in range(2, 10):
        print i, "*", j, "=", i*j
    print

Sample answer (H)

This is the kind of exercise where the solution can be as simple or as complicated as you want (or as time affords!). Dealing with human languages is always particularly tricky. Here's a sample answer that goes a bit further than simply looking at spaces:

sentence = raw_input("Enter a sentence: ")

count = 0
is_word = False

for letter in sentence:
    if letter in [" ", ".", ",", "-", "!", "?"]:
        is_word = False
    else:
        if not is_word:
            count += 1
        is_word = True

print "Number of words: ", count

Monday, January 31st

Code reading

strange_list = ["one", "potato", "", "bread", "red", ""]
has_empty_entries = False

for entry in strange_list:
if entry == "":
has_empty_entries = True
break if has_empty_entries: print "Error."
  • True/False: boolean variable
  • if has_empty_entries is a shortcut for if has_empty_entries == true
  • break was added later on in the example, and is meant to "break" out of the loop when encountered (so for instance you don't need to go through the 10,000 items in a list if you found what you wanted at the beginning).

File handling (Writing)

file = open('things.txt', 'w')

thing = raw_input("Enter the name of something you like: ")

while thing != "":
    file.write(thing + "\n")
    thing = raw_input("Enter the name of something you like: ")

file.close()
  • The 3 modes are 'r' (Read), 'w' (Write), 'a' (Append). Try with different mode to see the differences.
  • \n is a special character that creates a new line. . Try without it.
  • Always close resources, or you'll have some unpleasant surprises with files being locked, or data not being written.

File handling (Reading)

f = open('things.txt', 'r')
things = f.readlines() f.close() print "There are", len(things), "nice things" for t in things:     print t
  • readlines() will take everything from a file and put it into an array, with one line of the file in each array item.
  • readline() can be used to read only one line at a time.

File handling: Exercises

A.

You have 2 files to start with. They each contain a series of numbers. Read from both files at the same time, and add each number together. Write the results in a third file.

For example, if file1.txt contains:
1
2
3

and file2.txt contains:
2
3
4

You should end up with a results.txt file like this:
3
5
7

Tip: Just like int(variable) transforms a piece of text (string) into a number (integer), str(variable) will transform a number into text. You can only write text in a file.

B.

You have a file with a list of questions and answers. Every question is followed by its answer on the next line, like this:

question.txt
Who's the current Irish president?
Mary McAleese
What's the biggest book store in Ireland?
Hodges Figgis
What's the capital of Germany?
Berlin

Your program should read in this file and select a random question, and ask it to the user. If the user answers correctly, display "Won!" on screen. If the file is edited the new questions should automatically be picked up.

Tip: You'll likely find that even when writing the correct answer your program says the answer is incorrect. For now, compare against the user's reply + "\n" (for instance, if your variable name is "answer", compare against: answer + "\n"). It's annoying and we'll learn how to fix that in the 2nd part of today's lesson.

Code reading

What will be displayed on screen at line 12 (in bold)?

file = open("mycoolfile.txt", "w")
file.write("Hello,\n world\n!")
file.close()

count = 0

file = open("mycoolfile.txt", "r")
for line in file:
    count += 1
file.close()

print count

The problem

f = open('things.txt', 'r')
things = f.readlines()
f.close()

print "I like", things[0], ",", things[1], "and", things[2]

What's the problem here? Why is it happening?

=> Python reads in the newline (\n) that we added to write each thing on a different line.

Adding a dash of string manipulation

f = open('things.txt', 'r')
things = f.readlines()
f.close()

print "I like " + things[0].rstrip("\n") + ", " + things[1].rstrip("\n") + " and " + things[2].rstrip("\n")
  • rstrip() removes things from the right. lstrip() removes things from the left. strip() remove things from both sides. Have a look at the documentation to learn more about it (see next section).

String manipulation

We've seen and used strings a lot so far. Let's see what the Python documentation has to say about it.

From the offline folder, starting from index.html. Online, from http://docs.python.org.

Go to Library Reference, and find strings. You can see "str" is in sequence types. We saw last week that a string works like an array:

sentence = "Python is cool"
for letter in sentence:
    print letter
  • Major difference is that strings are immutable. You can read, but can't change them: sentence[0] = "L" will fail (try!)
  • Still, looking at "Operations" there is a lot of things we can do. Testing from the interpreter:
>>> sentence = "Python is cool"
>>> print sentence[0:6]
Python
>>> print sentence[1:6]
ython
>>> 'a' in sentence
False
>>> 'o' in sentence
True
>>> sentence.index('n')
5
>>> sentence.count('n')
1
>>> sentence.count('o')
3

Moving further down the documentation we see 5.6.1 Methods, this is where we'll spend most of our time for the exercises, and in general. Let's have a look at replace.

>>> sentence.replace("Python", "Cake") 
'Cake is cool' 
>>> print sentence 
Python is cool 
>>> sentence = sentence.replace("Python", "Cake") 
>>> print sentence 
Cake is cool 
>>> sentence = sentence[0:4] + "nom!"
>>> print sentence 
Cakenom! 

Remember, strings are immutable. When you call "replace" it actually creates a new string. Therefore if you want to change your sentence, you need to assign it to itself (e.g. sentence = sentence.replace("Python", "Cake")) or create a new variable to store it.

String manipulation: exercises

The list of exercises was longer but there wasn't much time to go through them. Because attendance was lower than usual, we will be looking at this and today's topics again next week.

A.

Write a program that counts how many times the word "Python" and the word "library" are used in the main page of the documentation -> Python_HTML_doc/index.html.

Here are the answers so you can check your program:

Python count: 22
Library count: 1

Extra: Make sure your count includes every occurrence of the two words no matter their case. Here are the numbers you should get back:

Python count: 35
Library count: 2

B.

Get a word from the user. Check if the word is a palindrome. (A palindrome is a word that is the same no matter which side it is read from, for example "Mom", "noon", "radar".) Extra: Make sure it works even if the case is different (e.g. "Mom")

Something useful

data = "5,6,7,12,4" # Assume this comes from a file, e.g. Excel/spreadsheet CSV export. Very handy.
data_list = data.split(",") # Breaks a string into an array. Look at the documentation for more info.

print data_list

for num in data_list:
    print int(num) * int(num)

data = "-".join(data_list) # Can choose to join on a comma or space or anything.
print data

Monday, February 7th

As mentioned earlier, we went over the same material: file handling, and learning to use the documentation to find various string manipulation functions.

Here are the rest of the string manipulation exercises.

String manipulation: exercises (cont'd)

C.

Ask the user to write something. If what they write is a number, multiply it by two. If it's a word, print it in all capital letters. Extra: If it's only white space or the user simply presses enter, ask again.

Examples of program output (user input is in bold):
Please write something: abcdef
ABCDEF
--
Please write something: 5
10

D.

Get a sentence from the user. Rewrite it with the first letter of every word capitalised and the rest of the word in lower case.

Examples of program output (user input is in bold):
Please enter some text: pyTHon is COOL
Python Is Cool

E.

Ask the user for a number. Check that the user really gave you a number, removing everything that is not a number (so that the int() conversion would work). If there was no number in the input, write an error message.

Examples of program output (user input is in bold):
Please enter a number: b7er
Number is: 7
--
Please enter a number: abcdef
This is not a number!

F.

Get some text from the user. Check if the input is in alphabetical order.

Examples of program output (user input is in bold):
Please enter some text: abef
Not alphabetical.
--
Please enter some text: abcdef
Input is in alphabetical order.


Monday, February 14th

Cancelled due to teacher sickness. I sent a few book recommendations instead:

  • How to Think Like a Computer Scientist - Tries to teach how to debug and other useful programming skills in parallel to programming concepts (in Python).
  • Invent Your Own Computer Games with Python - Go through the concepts we've been going through and more, but using simple games as examples and exercises
  • Learn Python the Hard Way - A different way of learning how to program, where you're only given a few explanations and told to figure out the rest on your own. Not to everyone's taste but I think it can work for some learners.

Monday, February 21st

Code reading

What will this print? Read the documentation on rstrip().

sentence = "Python is cool"

print sentence.rstrip("l") # Python is coo
print sentence.rstrip("ol") # Python is c
print sentence.rstrip("o") # Python is cool

New data structure: Dictionaries

# attendance
students = { 'Bob' : True,
            'Rick': False }             print students['Bob']             students['Bob'] = True # Single element
  • Dictionaries can also be called maps
  • Dictionaries can have a string as (instead of) an index.
  • On the left handside is the key (e.g. 'Bob'). On the right handside is the value. Keys must be unique.
  • You could combine a dictionary with lists or with another dictionaries to have access to more data, e.g.
grades['Bob'] = [67, 56, 33]
print grades['Bob'][0] # 67

Functions

As far as we're concerned, for our purpose methods and functions are the same thing.

def square(number): 
    result = number * number 
    return result
    
print square(2) 
print square(3) 
print square(4) 
print square(5)
  • A function is a self-contained section of code that can be reused over and over, useful to structure your code.
  • Between the parenthesis are the parameters, also called arguments. These are variables that will contain the value you use to "call" the function.
  • A function must be defined before you can use it.
  • The content of a function is ignored until the function called -- if you remove the 4 square statement at the end, nothing will happen when executing the file.

Import

You can now create your own libraries of functions to import into your programs. If the name of the file where you defined your square() function is mycoolfunctions.py, you can use it as follow from another file:

import mycoolfunctions
print mycoolfunctions.square(5)

Exercises (Dictionaries & Functions)

A.

In the documentation, there is a file named "license.txt" in the directory Python_HTML_doc/_sources -- here online. Write a Python program that opens that file and counts the occurrences of every word (case-insensitive) in the text. When this is done, display the results for each word, with the count besides the word.

Extra: Display the results in alphabetical order

Extra: Handle the punctuation so that all words are counted properly (e.g. "author," and "author" are considered to be the same word)

Here are a few examples to compare your results against (taking the 2 Extras into account):

business 5 
but 21 
button 1 
by 48 
byte 1 
c 19 
c-program 1 
ca 1 
california 8 
called 2 
calls 1 
can 2 
cannot 2 

B.

A few weeks back we wrote a small program that displays on screen the multiplication tables from 2 to 10. Based on the same idea, write a small function that takes a number as a parameter, and prints the multiplication table for that number from 2 to 10.

C.

Write a function that takes a number of seconds as a parameter, and returns a string "translating" that number into hours/minutes/seconds.

Example output, if your function is named "hours" and your program reads:

print hours(3600) 
print hours(1) 
print hours(74) 
print hours(7283) 

Running your program should result in the following output:

1h 0mn 0s 
0h 0mn 1s 
0h 1mn 14s 
2h 1mn 23s 

D.

You have a file that contains a combination of usernames and passwords, one per line with the following format:

username1:password1

Write a function, isAuthorised, that takes 2 parameters. Your program should call the function to check if the user entered a valid username and password, and give them 3 attempts to authenticate.

Sample answer (A)

With the 2 "extras" included.

import string

text = open("/home/julie/Python_HTML_doc/_sources/license.txt", "r")

words = {}

for line in text.readlines():
    for word in line.split():
        word = word.strip(string.punctuation)
        if not word.isspace() and len(word) > 0:
            if word.lower() in words:
                words[word.lower()] += 1
            else:
                words[word.lower()] = 1

text.close()

for w in sorted(words.keys()):
    print w, words[w]
    i += 1

Sample answer (C)

def hours(seconds):
    if seconds < 0:
        return "Error"

    hours = 0
    minutes = 0

    if seconds >= 60:
        minutes = seconds/60
        seconds = seconds - (minutes * 60)

    if minutes >= 60:
        hours = minutes/60
        minutes = minutes - (hours * 60)


    return str(hours) + "h " + str(minutes) + "mn " + str(seconds) + "s"


print hours(3600)
print hours(1)
print hours(74)
print hours(7283)

Student request: Getting data from a url => urllib2

A tutorial in the Python documentation goes in excruciating details about this: Python doc index -> HOWTOs -> HOWTO Fetch Internet Resources Using urllib2. This goes into authenticating into websites, handling server errors and submitting form data. We really only need the first 3 line example :)

A very quick crash course in HTML:

example1.html
<html>
    <head>
        <title>An HTML page</title>
    </head>
    
    <body>
        <p>An example <b>page</b> with some text in it.</p>
        
        <br/>
        
        <p><a href="http://www.google.com">Link to Google</a></p>
        <p><a href="example2.html">A local link</a></p>
    
    
    </body>
</html>example2.html
<html>
    <head>
        <title>Another HTML page</title>
    </head>
    
    <body>
        <p>Page 2.</p>
        
        <p><a href="#test">Next</a></p>      
        
        <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>        <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
        
        <a name="test">Hello</a>    
    </body>
</html>

Back to urllib2:

import urllib2

response = urllib2.urlopen('http://www.google.com')
html = response.read()

print html
  • This gets you one file.
  • You'll need to get the urls from the html file yourself:
    • http://www.example.com/blah.html
    • /blah.html ( appends blah.html to the url rool, e.g. http://www.example.com/blah.html)
    • blah.html (depends where you are in the site, e.g. if you're in http://www.example.com/my/folder/meh.html, this would mean http://www.example.com/my/folder/blah.html)
  • <a href="#blah">Link</a> means the link is in the same file so you don't have to care about it.

Exercise

Build a list of the urls on the Python index.html documentation, and print it on screen.

Student request: Installing additional Python libraries

Go to Pypi, the Python package index. Find if the library you want is in there.

If it is, go back to the Pypi main page, click on "Tutorial" and follow the instructions to install easy_install. Once that is done and you've updated your path appropriately, you will be able to install anything from Pypi just by writing easy_install packageName into your command line. Any required dependency will also be installed.

If the library you want is not in there, find a README or INSTALL text file in the package you download that'll hopefully tell you where to manually put the files.

Sekrit tip: If you get sick of trying to get the urls from your HTML, have a look at the BeautifulSoup HTML parser (easy_install BeautifulSoup) and read through its documentation. This is a very powerful and complex library, that may help with your problems, as well as create new ones.

Feedback form

Students were kind enough to fill in the following feedback form for me -- thank you for attending over the last few weeks, it's been a pleasure!

Overall impression: Meh        ∘    ∘    ∘    ∘    ∘     Good
Knowledge acquired: I didn't learn much     ∘    ∘    ∘    ∘    ∘     I learnt a lot

What did you expect when you signed up for the course? 
Did the course match your expectations?
Was there anything missing you would have liked us to look at?
Best/most interesting thing:
Least interesting thing/thing that didn't quite work:
Any idea or suggestion to make the course better?
Three words to describe the course:
Additional comments, feedback, doodles: