Learning
Python
Student Course Workbook
February, 2007
HTML Workbook Version 2.5.1
Copyright © Mark Lutz, 1997—2007
This is the course workbook root page. It contains all the material presented during
the class, source code for examples and lab exercises, and links to related
information on the Net. Click on unit
titles below to go to lecture unit pages. Click on the exercises title at the
bottom of the list below to go to lab exercises, or use the links at the end of
each lecture unit's page. Use your browser's "back" button to come
back to this index, or create a shortcut to this file on your machine. See also the CD-ROM distribution's "readme" file.
The paper workbook handouts (if
provided) are essentially the same as the electronic HTML version of the
workbook on the CD. The paper workbook
is simply a printed version of the HTML workbook on CD, but with minor
formatting changes and some optional-reading items deleted to save space. However, the HTML workbook also contains
active hyperlinks to sections and related information. In addition, the HTML workbook allows
examples to be cut-and-paste into a text editor or the Python command-line
(some example code is not in the CD's Examples directory). Therefore, the paper
workbook is generally used only for taking notes; students are encouraged to
follow along by viewing the HTML workbook in a web browser.
Lecture units
About this class
Daily scheduLE
Course topics
So what’s Python?
Why do people use Python?
Some quotable quotes
A Python history lesson
Advocacy News
What’s Python good for?
What’s Python not good for?
The compulsory features list
Python portability
On apples and oranges
Summary: Why Python?
How to run Python programs
Configuration details
Module files: a first look
The IDLE interface
Other python ides
Time to start coding
The ‘big picture’
Numbers
Strings
Lists
Dictionaries
Tuples
Files
General object properties
Summary: Python’s type hierarchies
Built-in type gotchas
General concepts
Assignment
Expressions
Print
If selections
Python syntax rules
Truth tests
While loops
Break, continue, pass, and the loop else
For loops
Loop coding techniques
Comprehensive examples
Basic coding gotchas
Preview: program unit statements
Function basics
Scope rules in functions
More on “global”
More on “return”
More on argument passing
Special argument matching modes
Odds and ends
Function design concepts
Functions are objects: indirect calls
Function gotchas
Optional case study set functions
Module basics
Module files are a namespace
Name qualification
Import variants
Reloading modules
Odds and ends
Module design concepts
Modules are objects: metaprograms
Module gotchas
optional Case study: a shared stack module
class basics
A more realistic example
Using the class statement
Using class methods
Customization via inheritance
Specializing inherited methods
Operator overloading in classes
Namespace rules: the whole story
OOP: inheritance and composition
Classes are objects: factories
Methods are objects: bound or unbound
Odds and ends
Class gotchas
optional Case study: a set class
Summary: OOP in Python
Exception basics
First examples
Exception idioms
Exception catching modes
Matching variations
Exception gotchas
debugging options
Inspecting name-spaces
Dynamic coding tools
Timing and profiling Python programs
Packaging programs for delivery
Summary: Python tool-set layers
System Modules Overview
Arguments, Streams, shell variables
file tools
directory tools
forking processes
python thread modules
fork versis spawnv
example: make forward-link files
Example: regression testing
Example: packing/unpacking text files
Python GUI Options
The Tkinter ‘hello world’ program
Adding buttons, frames, and callbacks
Getting input from a user
More details
Building GUIs by subclassing frames
Reusing GUIs by subclassing and attaching
Advanced widgets: Images, grids, and more
Sexier examples
Tkinter odds and ends
Object persistence: shelves
Storing class instances
Pickling objects without shelves
Using simple dbm files
Shelve gotchas
Python SQL DATABASE API
ZODB object-oriented database
Persistence odds and endS
String objects: review
Splitting and joining strings
Regular expressions
Parsing languages
Using sockets in Python
The FTP module
email processing
Other client-side tools
Writing server-side CGI scripts
The Grail web browser
JPython: Python for Java systems
Active Scripting and com
Other Internet-related tools
Review: Python tool-set layers
Stuff Guido already wrote
Why integration?
The ‘big picture’ revisited
Integration modes
A simple C extension module
C module structure
Binding C extensions to Python
Data conversions: Python Û C
C extension types
Using C extension types in Python
Wrapping C extensions in Python
Writing extensions in C++
swig example (pp2e)
Python and rapid development
General embedding concepts
Running simple code strings
Calling objects and methods
Running strings: results & name-spaces
Other code string possibilities
Registering Python objects and strings
Accessing C variables in Python
C API equivalents in Python
Running code files from C
Precompiling strings into byte-code
Embedding under C++
More on object reference counts
Integration error handling
Automated integration tools
Python portability
Major python packages
Internet resources
Python books
Python in the news: articles, chapters
Python conferences and services
And finally
Labwork and examples
Lab 1: Using the interpreter
Lab 2: Types and operators
Lab 3: Basic statements
Lab 4: Functions
Lab 5: Modules
Lab 6: Classes
Lab 7: Exceptions and built-in tools
Lab 8: System interfaces and GUIs
Lab 9: Persistence
Lab 10: Text processing and the Internet
Lab 11: Extending Python in C/C++
Lab 12: Embedding Python in C/C++
Lab 1: Using
the Interpreter
Lab 2: Types
and Operators
Lab 3: Basic
Statements
Lab 4:
Functions
Lab 5: Modules
Lab 6: Classes
Lab 7: Exceptions and
built-in toolS