Announcements | Summary | Readings | Software | Schedule

Programming in Python

Spring Term, 2012
(10 Sessions) Wednesdays 6 - 9 pm, starting Wednesday March 28th.

This course is based on a combination of the public course: Programming in Python, Autumn 2011 and some content from Internet Programming in Python, Winter 2011


Announcements and updates:
6/06 - Added materials for
week 10.
6/03 - Added week 10 readings.
5/28 - Finalized week 9 readings.
5/23 - Added materials for week 8.
5/16 - Added materials for week 7.
5/09 - Added materials for week 6.
4/25 - Added materials for week 5.
4/25 - Added materials for week 4.
4/16 - Added Lightning Talk schedule.
4/15 - Added optional unicode article and Learn Python the Hard Way references for week 3.
4/11 - Added materials for week 2.
3/29 - Added Learn Python the Hard Way references for week 1 and week 2.
3/28 - Added materials for week 1.

The schedule is updated every week, consult frequently.


Course objectives: Introduce the Python language, its most important libraries, and its recommended programming styles and idioms. Teach how to solve typical programming problems in Pythonic style. Survey some exemplary Python applications and systems.

Prerequisites: No previous Python experience is required. This course is not intended for absolute beginners in programming, but does include a self-contained review of elementary features. Students must be able to use a command line, edit a text file, and download and install software. Students should have some prior exposure to programming in any language, sufficient to write very simple programs or scripts that use variables, conditionals (if ...), and iteration (loops).

Textbooks: The textbook comes in two versions: a printed book named Python for Software Design, and a free online version named Think Python. Despite the different titles, the two versions have the same contents.

Instructor: Brian Dorsey.
Brian Dorsey is a database and Python developer with over 10 years of experience using Python professionally. He currently works at Vulcan Inc., developing command line tools, simple web applications, Windows services, HTTP/JSON APIs and the occasional iPhone prototype. He is excited about information, databases, user experience, testing and glue code. Brian is a co-organizer of the Seattle Python Interest Group (www.seapig.org) and has given several talks and tutorials at conferences and user groups.

Technology Requirements: Students must have access to a computer for their assignments and projects, where they can install software (the course does not provide a computer laboratory). Older computers and computers with modest resources (including netbooks) will work. Any popular operating system will work, including Windows, Mac OS X, and Linux. It is recommended that students have a portable computer to bring to class. Internet access will be provided at classes.

Assessment criteria: The course is graded Pass/Fail, based on satisfactory completion of required programming assignments and classroom presentations. Attendance is required; more than two unexcused absences will result in a Fail.


Textbook

The textbook comes in two versions, a printed book:

Python for Software Design: How to Think Like a Computer Scientist by Allen B. Downey. Cambridge University Press, 2009.

and a free online version:

Think Python: How to Think Like a Computer Scientist

Despite the different titles, the two versions have the same contents, including the same chapter, section, and exercise numbers. You may use the version you prefer.

This text is an excellent introduction to Python language fundamentals and semantics. There are many features and topics it does not discuss. We will discuss them in class and assign supplementary readings.

Supplemental Textbook

Learn Python the Hard Way by Zed Shaw.

It is available for free online, and for pay in various electronic and physical formats.

This book introduces Python through hands-on exercises and repetition. It is an excellent introduction to both Python and practical programming skills.

Summaries

Quick Python Script Explanation for Programmers (one page)
Learn Python in 10 minutes
NanoPy

Reference

Python 2.7 Quick Reference (awesomely dense and complete)
Python 2.x documentation (official documentation from python.org)

Supplementary texts

The Python Tutorial (from python.org)

IDLE Interactive Development Environment

Reference from python.org
Quick tour with screenshots

Other resources

Examples and Resources (other courses and books, sample code, notable Python libraries and scriptable applications)


Software

Students will need Python installed on their computers. Python comes already installed on Macs and most Linux distributions.

There are two different "current" versions of Python, 2.x and 3.x. We will be using 2.x, where x means any sufficiently recent version. 2.7 is most recent, but 2.6 will also work.

The current Python 2.x version is available here. I use this source for Windows. For the Mac, I use homebrew. For Linux, I use the distro's package manager (Synaptic or apt-get on Ubuntu, for example).


Schedule and Assignments

Wednesdays 6 - 9 pm, starting Wednesday March 28th (10 Sessions).

Additional topics and readings will be added, consult frequently.

Read the assignment and do the assigned exercises in the week before class. Here PySD/TPy refers to the textbook, either Python for Software Design (printed) or Think Python (online). Both versions use the same chapter numbers (but in the TPy web pages, Chapter 2 is in file book003.html etc.) LPTHW refers to Learn Python the Hard Way.

WeekDateTopics Assignments due
1March 28 Introductions.
Some Python applications and systems.
Installing Python.
Using the command interpreter and development environment.
Finding and using the documentation. Getting help.
Variables, values, expressions, and assignment.

Code and data:
Week 1 files
readings:
PySD/TPy, Chapters 1, 2,

assignment:
Come to class. ;)

extra:
"Use your friends. Keep it simple. Play."
Teach Yourself Programming in Ten Years

LPTHW: ex1, ex2, ex3, ex4
April 4 Class cancelled
2April 11 Functions. Definition and use. Arguments.
Block structure. Scope.
Modules and import.
Boolean expressions.
Conditionals and control flow.
Iteration and recursion.

Code and data:
Week 2 files
readings:
PySD/TPy, Chs. 3, (4)

PySD/TPy 5, 6, 7

assignment:
assignment 2

extra:
LPTHW: for optional extra practice with the concepts
functions: ex11, ex12, ex13, ex18, ex19, ex21
boolean logic: ex27, ex28
if then else: ex29, ex30, ex31
iteration: ex33
3April 18 Sequences.
Strings.
Files.
Exceptions.
Text Processing.
Regular expressions.
Unicode.

Lightning Talks: Jared O, Mark T, Todd B
readings:
PySD/TPy, Chs. 8, 9, 14

assignment:
Six more CodingBat exercises.

extra:
String methods
RegEx
How-To
Unicode How-To, more
The Absolute Minimum Every Software Developer Absolutely,
Positively Must Know About Unicode
and Character Sets (No Excuses!)


LPTHW: for optional extra practice with the concepts
strings: ex5, ex6, ex7, ex8, ex9, ex10
raw_input(), sys.argv: ex12, ex13, ex14 (needed for files below)
files: ex15, ex16, ex17,
4April 25 Sequences again.
Tuples, Lists, Dictionaries, Sets.
Mutability.
Aliasing.
Argument passing.
List comprehensions.
Data type case studies and review.

Lightning Talks: Brett W, Carolyn H, Swetha G
readings:
PySD/TPy, Chs. 10, 11, 12, 13

Python Tutorial, sections 3.1.4, 5

Spelling corrector

assignment:
CodingBat - 12 more string & list problems
or
write a script which does something useful (to you) and reads
and writes files. Very, very small scope is good.
5May 2 Build a dynamic HTTP server from scratch.
We will cover just enough networking and HTTP to build a simple working server.
readings:
Very quick overview of web fundamentals
Internet Protocol Suite
Internet Socket
HTTP Made Really Easy (Only the HTTP 1.0 section, 1.1 optional)

assignment:
Coding Kata 14 - Dave Thomas
Send me one of your experiments with this kata,
and a bit of output from it.

extra:
sockets module
skim this (Python, batteries included!):
python internet modules
6May 9 Classes, instances, and methods.
Object-oriented programming.
Inheritance and duck typing.

Lightning Talks: James A, Kangie C, Ton O
readings:
PySD/TPy, Chs. 15, 16, 17, 18

assignment:
Update thirty_minute_webserver.py
  • Instead of showing the content of .py files,
    run the script and return its' output instead.
    (the stdlib subprocess.Popen() will be useful)
  • test with script which outputs the time (print_time.py)
  • update the print_time.py script to output html
7May 16 Special attributes and methods.
Iterators and Generators.
Decorators.

Lightning Talks: Brad D, Leena A, Jeff G
readings:
A Guide to Python's Magic Methods
The Python yeild keyword explained
   (just the question and the top answer)
Descriptor HowTo Guide

assignment:
  • For a portion of the system you're responsible for testing:
    Make a few classes to represent that portion.
    (No more than three or four classes)
  • Imagine that these classes can automatically control the system,
    what methods would you find most useful?
  • Write a few of them with a mock implementation.
    (accept parameters, update state, print out current state, etc)
  • Write a bit of code using these objects to set up
    an (imaginary) test environment.

extra:
Special Methods, learn about __str__, __add__
and their many many cousins.
Generator Tricks for Systems Programmers
Python Tutorial, Sections 9.9 - 9.11

8May 23
The debugger.
Packages.
PyPI.
Installation.
Distribution.

Lightning Talks: John dM, Nate K, Walt J
readings:
pdb - Interactive Debugger
Modules and Packages
   (skim the parts you know already)
Installation ("Introduction" and
    "Standard Build and Install" sections only)
... more TBD?

assignment:
Find and install a Python package and report your experience.
Report these items:
  1. The name of the package
  2. Location where you found the package
  3. The format of the downloaded package, if any
    (.msi, .dmg, .tar.gz, ... or 'none')
  4. The installation program you used
    (distutils, pip, easy_install, apt, macports ...)
  5. Whether the installation was successful
If the installation was not successful, you don't have
to fix it if you don't want to -- just report that it
didn't work. If you do fix it, report that.

extra:
CheeseShop Tutorial (PyPI)
9May 30 Databases - relational and otherwise.
(a tour of information storage methods)


Lightning Talks: Jake M, Todd H
readings:
(Wikipedia) Relational Database
(Wikipeia) SQL
Is the relational database doomed?
NOSQL at Netflix
I can't wait for NOSQL to die
NOSQL is software darwinism
Why NOSQL will not die
NOSQL Comparison

assignment:
  • Look at bookdb.py.
  • Make a new class which connects to a database
    which actually has this data in it.
  • Two database drivers are in the stdlib: sqlite3, anydbm.
    Use them, or another database you prefer.
  • Send me your implementation, and the database file
    if you used sqlite3 or anydbm.
extra:
Redis Tutorial by Simon Willison
10June 6 Python testing tools
readings:
Python stdlib - doctest (This section only)
   (Sections 25.2.1, 2 & 8)
Python stdlib - unittest
   (Sections 25.3.1, 2, 3, 4, 5 & 7 especially the list of methods)
py.test - Getting Started (This section only)
Mock - Getting Started (This section only)
PEP 8 - Style Guide for Python Code

assignment:
None this week!

extra:
Read through this list of tools:
Python Testing Tools Taxonomy
Pick 3 and read more about them. For each:
  • What problems(s) does it address?
  • How does it do it?
  • Why should we care?
  • Where do we find out more?
Read more deeply into the doctest, unittest, nose, py.test or mock documentation.

Announcements | Summary | Readings | Software | Schedule


Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.