Target Audience: Intermediate
This class is for programmers who are already experienced with another programming
language such as C, C++, Java, Perl, PHP, etc.
No experience with Python is assumed,
but don't be misled by the word "Introduction."
This is a serious hands-on course in which you will be writing
programs, working with datafiles, and exploring a wide range of
topics. Come ready to code. [ Am I prepared? ]
Price: $2500
What's Included?
- A printed copy of the course notes.
- A copy of the "Python Essential Reference, 4th Ed."
- Lunch at local restaurants
- Snacks
[ Register | More Information | FAQ]
|
Introduction To Python
[3 days] An intense no-bull Python course for programmers, sysadmins, scientists, and engineers who
want to know how to use Python to solve all manner of practical
problems. Topics are aimed at tasks that you face on a day-to-day
basis. For example, analyzing data files, encoding/decoding various
file formats, accessing databases, scraping web pages, automating
system tasks, integrating Python with legacy software, and more.
Even if you already know some
Python, you will walk away from this course with new insight and ideas.
Major topics include:
- An introduction to python
- Working with data
- Program organization and functions
- Modules and libraries
- Classes and objects
- Testing, debugging, and profiling
- Iterators and generators
- Text processing and parsing
- Files and the file system
- Processes and subprocesses
- XML parsing
Detailed Course Outline
Day 1
- Introduction to Python.
An introduction to the Python programming language. Covers details of
how to start and stop the interpreter and write programs. Introduces
Python's basic datatypes, files, functions, and error handling.
- Working with Data.
A detailed tour of how to represent and work with data in Python.
Covers tuples, lists, dictionaries, and sets. Students will also
learn how to effectively use Python's very powerful list processing
primitives such as list comprehensions. Finally, this section covers
critical aspects of Python's
underlying object model including variables, reference counting, copying,
and type checking.
- Program Organization and Functions.
More information about how to organize larger programs into functions. A major focus
of this section is on how to design functions that are reliable and can be easily
reused in other settings. Also covers technical details of functions including
scoping rules, documentation strings, and anonymous functions.
Day 2
- Modules and Libraries. How to organize programs into
modules and details on using modules as a tool for creating extensible
programs. This section concludes with a overview of some of the most
commonly used library modules and instructions on how to install third
party library modules. Some of the standard library modules covered
in this section include those related to the file system and file
handling, Tkinter (used to write GUIs), the Python database API (used
to connect Python to relational database systems), and the logging
module.
- Classes and Objects. An introduction to object-oriented
programming in Python. Describes how to create new objects, overload
operators, and utilize Python special methods. Also covers basic
principles of object oriented programming including inheritance and
composition.
- Inside the Python Object Model. A detailed look at how
objects are implemented in Python. Major topics include object
representation, attribute binding, inheritance, memory management, and
special properties of classes including properties, slots, and private
attributes.
- Testing, Debugging, and Software Development Practice.
This section discusses many isses that are considered important to
Python software development. This includes effective use of
documentation strings, program testing using both the doctest and
unittest modules, and effective use of assertions. The Python
debugger and profiler are also described.
Day 3
- Iterators and Generators.
Covers the iteration protocol, iterable objects, generators and generator
expressions.
A major focus of this section concerns the use of generators to set up data processing pipelines--a
particularly effective technique for addressing a wide variety of common systems programming
problems (e.g., processing large datafiles, handling infinite data streams, etc.).
- Working with Text. A more in-depth look at how to efficiently parse and generate text
data in Python. Topics include string splitting, string stripping,
string joining, and template strings. This section also covers the re
module, Python's module for regular expression pattern matching and
substitution.
- Binary Data Handling and File I/O. How to work with
binary-encoded data in Python. Topics include binary file I/O as
well as the struct and array modules.
- Python Integration Primer. A survey of how Python is able
to interact with programs written in other programming languages.
Topics include subprocesses, support for common data interchange formats (e.g., XML), network programming, accessing C code, COM extensions, Jython, and IronPython.
- Advanced Topics. An assortment of more advanced programming
techniques. Topics include variable argument functions, anonymous functions and lambda,
decorators, and packages.
Course Materials
Students will receive a bound 300-page fully indexed set of lecture notes along with a complete set of more than 50 class exercises (distributed
electronically). All class exercises come with solution code for later study and for use during the class.
Slide Topic Index
The following table, generated automatically from the presentation slides,
gives much more detail about the material to be covered. I am always
making improvements to course material so this outline is subject to change
at any time.
0. Course Setup
Course Setup | 0-1 |
Required Files | 0-2 |
Setting up Your Environment | 0-3 |
Class Exercises | 0-4 |
General Tips | 0-6 |
Using IDLE | 0-7 |
Running IDLE (Windows) | 0-8 |
Running IDLE (Mac/Unix) | 0-9 |
1. Introduction to Python
Introduction to Python | 1-1 |
Where to Get Python? | 1-2 |
What is Python? | 1-3 |
Why was Python Created? | 1-4 |
Python Influences | 1-5 |
Some Uses of Python | 1-6 |
Python Non-Uses | 1-7 |
Getting Started | 1-8 |
Running Python | 1-9 |
IDLE | 1-10 |
IDLE on Windows | 1-11 |
IDLE on other Systems | 1-12 |
The Python Interpreter | 1-13 |
Interactive Mode | 1-14 |
Interactive Mode in IDLE | 1-16 |
Getting Help | 1-17 |
Creating Programs | 1-19 |
Running Programs (IDLE) | 1-23 |
Running Programs | 1-24 |
A Sample Program | 1-25 |
An IDLE Caution | 1-29 |
Python 101 : Statements | 1-31 |
Python 101 : Comments | 1-32 |
Python 101: Variables | 1-33 |
Python 101: Keywords | 1-34 |
Python 101: Case Sensitivity | 1-35 |
Python 101: Looping | 1-36 |
Python 101 : Indentation | 1-37 |
Python 101 : Conditionals | 1-39 |
Python 101 : Relations | 1-40 |
Python 101 : Printing | 1-41 |
Python 101 : User Input | 1-42 |
Python 101 : pass statement | 1-43 |
Python 101 : Long Lines | 1-44 |
Basic Datatypes | 1-46 |
Numbers | 1-47 |
Booleans (bool) | 1-48 |
Integers (int) | 1-49 |
Long Integers (long) | 1-50 |
Integer Operations | 1-51 |
Integer Division | 1-52 |
Floating point (float) | 1-53 |
Floating point | 1-54 |
Floating Point Operators | 1-55 |
Converting Numbers | 1-56 |
Strings | 1-57 |
String Escape Codes | 1-58 |
String Representation | 1-59 |
More String Operations | 1-61 |
String Methods | 1-62 |
More String Methods | 1-63 |
String Mutability | 1-64 |
String Conversions | 1-65 |
String Splitting | 1-67 |
Lists | 1-68 |
Lists (cont) | 1-69 |
More List Operations | 1-70 |
List Removal | 1-71 |
List Sorting | 1-72 |
File Input and Output | 1-74 |
Looping over a file | 1-75 |
Type Conversion | 1-77 |
Simple Functions | 1-78 |
Library Functions | 1-79 |
Exception Handling | 1-80 |
Exceptions | 1-81 |
dir() function | 1-83 |
dir() Example | 1-84 |
Summary | 1-85 |
2. Working with Data
Working with Data | 2-1 |
Overview | 2-2 |
Primitive Datatypes | 2-3 |
None type | 2-4 |
Data Structures | 2-5 |
Tuples | 2-6 |
Tuple Use | 2-7 |
Tuples (cont) | 2-8 |
Tuple Packing | 2-9 |
Tuple Unpacking | 2-10 |
Tuple Commentary | 2-11 |
Tuples vs. Lists | 2-12 |
Dictionaries | 2-13 |
Containers | 2-17 |
Lists as a Container | 2-18 |
Dicts as a Container | 2-19 |
Dict : Looking For Items | 2-20 |
Dicts and Lists | 2-21 |
Formatted Output | 2-23 |
String Formatting | 2-24 |
Format Codes | 2-25 |
String Formatting | 2-26 |
Working with Sequences | 2-28 |
Sequence Slicing | 2-30 |
Extended Slices | 2-31 |
Sequence Reductions | 2-32 |
Iterating over a Sequence | 2-33 |
Iteration Variables | 2-34 |
break and continue | 2-35 |
Looping over integers | 2-36 |
Caution with range() | 2-37 |
enumerate() Function | 2-38 |
for and tuples | 2-40 |
zip() Function | 2-41 |
Using zip() | 2-43 |
List Processing | 2-45 |
List Comprehensions | 2-46 |
List Comp: Examples | 2-49 |
Historical Digression | 2-50 |
List Comp. and Awk | 2-51 |
Big Idea: Being Declarative | 2-52 |
More details on objects | 2-54 |
The Issue with Assignment | 2-55 |
Assignment Example | 2-56 |
Reassigning Values | 2-58 |
Some Dangers | 2-59 |
Identity and References | 2-60 |
Shallow Copies | 2-61 |
Deep Copying | 2-62 |
Names, Values, Types | 2-63 |
Type Checking | 2-64 |
Everything is an object | 2-65 |
First Class Objects | 2-66 |
Summary | 2-67 |
3. Program Organization and Function
Program Organization and Functions | 3-1 |
Overview | 3-2 |
Observation | 3-3 |
What is a "Script?" | 3-4 |
Problem | 3-5 |
Defining Things | 3-6 |
Defining Functions | 3-7 |
What is a function? | 3-8 |
Function Definitions | 3-9 |
Bottom-up Style | 3-10 |
A Definition Caution | 3-11 |
Function Design | 3-13 |
Function Arguments | 3-14 |
Default Arguments | 3-15 |
Calling a Function | 3-16 |
Keyword Arguments | 3-17 |
Mixed Arguments | 3-18 |
Design Tip | 3-19 |
Return Values | 3-22 |
Multiple Return Values | 3-23 |
Side Effects | 3-24 |
Design Tip | 3-25 |
Understanding Variables | 3-26 |
Local Variables | 3-27 |
Global Variables | 3-28 |
Modifying Globals | 3-29 |
Design Tip | 3-31 |
More on Functions | 3-33 |
Error Checking | 3-34 |
Documentation Strings | 3-37 |
Docstring Benefits | 3-38 |
Exceptions | 3-40 |
Builtin-Exceptions | 3-44 |
Exception Values | 3-45 |
Syntax Caution | 3-46 |
Catching Multiple Errors | 3-47 |
Catching All Errors | 3-48 |
Exploding Heads | 3-49 |
A Better Approach | 3-50 |
finally statement | 3-51 |
Program Exit | 3-52 |
4. Modules and Libraries
Modules and Libraries | 4-1 |
Overview | 4-2 |
Modules | 4-3 |
Namespaces | 4-4 |
Globals Revisited | 4-5 |
Common Confusion | 4-6 |
Module Execution | 4-7 |
Main Functions | 4-8 |
Main Module | 4-9 |
__main__ check | 4-10 |
Module Loading | 4-12 |
Locating Modules | 4-13 |
Module Search Path | 4-14 |
Import Process | 4-15 |
Using Modules | 4-17 |
Modules are Objects | 4-18 |
What is a Module? | 4-19 |
import as statement | 4-20 |
from module import | 4-22 |
from module import * | 4-23 |
Be Explicit | 4-25 |
Globals, Once More | 4-26 |
Standard Library | 4-28 |
sys module | 4-29 |
sys: Standard I/O | 4-30 |
sys: Command Line Opts | 4-31 |
Command Line Args | 4-32 |
math module | 4-33 |
copy Module | 4-34 |
os Module | 4-35 |
Environment Variables | 4-36 |
Getting a Directory Listing | 4-37 |
os.path Module | 4-38 |
File Tests | 4-39 |
Pathnames | 4-40 |
File Metadata | 4-41 |
Directory Walking | 4-42 |
Shell Operations (shutil) | 4-43 |
time module | 4-44 |
datetime module | 4-45 |
pickle Module | 4-47 |
shelve module | 4-49 |
sqlite3 Module | 4-50 |
sqlite3 Example | 4-51 |
sqlite3 Module | 4-53 |
Commentary | 4-54 |
Third Party Modules | 4-56 |
Some Notable Modules | 4-57 |
Installing Modules | 4-58 |
Platform Native Install | 4-59 |
OS Package Manager | 4-60 |
Manual Installation | 4-61 |
setuptools/distribute | 4-62 |
Commentary | 4-63 |
Summary | 4-64 |
5. Classes and Objects
Classes and Objects | 5-1 |
Overview | 5-2 |
OO in a Nutshell | 5-3 |
The class statement | 5-4 |
Instances | 5-5 |
__init__ method | 5-6 |
Instance Data | 5-7 |
Methods | 5-8 |
Calling Other Methods | 5-9 |
Inheritance | 5-11 |
Inheritance Example | 5-13 |
Using Inheritance | 5-15 |
object base class | 5-16 |
Inheritance and | 5-17 |
Inheritance and methods | 5-18 |
Calling Other Methods | 5-19 |
Multiple Inheritance | 5-20 |
Special Methods | 5-22 |
Methods: String Conv. | 5-23 |
Methods: Item Access | 5-24 |
Methods: Containment | 5-25 |
Methods: Mathematics | 5-26 |
Odds and Ends | 5-27 |
Defining Exceptions | 5-28 |
Method Invocation | 5-29 |
Bound Methods | 5-30 |
Unbound Methods | 5-31 |
Attribute Accesss | 5-32 |
Summary | 5-33 |
6. The Inner Workings of Python Objects
The Inner Workings of Python Objects | 6-1 |
Overview | 6-2 |
Dictionaries Revisited | 6-3 |
Dicts and Functions | 6-4 |
Dicts and Modules | 6-5 |
Dicts and Objects | 6-6 |
Dicts and Instances | 6-7 |
Dicts and Classes | 6-9 |
Instances and Classes | 6-10 |
Attribute Access | 6-12 |
Modifying Instances | 6-13 |
Reading Attributes | 6-15 |
How Inheritance Works | 6-18 |
Reading Attributes | 6-19 |
Single Inheritance | 6-20 |
Multiple Inheritance | 6-21 |
Classes and Encapsulation | 6-23 |
A Problem | 6-24 |
Python Encapsulation | 6-25 |
Private Attributes | 6-26 |
Private Methods | 6-27 |
Accessor Methods | 6-28 |
Properties | 6-29 |
Uniform Access | 6-33 |
Properties | 6-34 |
Decorators | 6-35 |
__slots__ Attribute | 6-36 |
Memory Management | 6-38 |
Instance Creation | 6-39 |
__new__() method | 6-40 |
Instance Deletion | 6-41 |
Object Deletion: Cycles | 6-42 |
Garbage Collection | 6-43 |
__del__ method | 6-44 |
7. Testing and Debugging
Testing and Debugging | 7-1 |
Overview | 7-2 |
Testing Rocks, Debugging Sucks | 7-3 |
Testing: doctest module | 7-4 |
Using doctest | 7-5 |
Self-testing | 7-7 |
Testing: unittest | 7-9 |
Using unittest | 7-10 |
Running unittests | 7-13 |
unittest comments | 7-14 |
logging Module | 7-16 |
Exceptions Revisited | 7-17 |
Using Logging | 7-19 |
Logging Basics | 7-20 |
Logging Configuration | 7-21 |
Big Picture | 7-23 |
Assertions | 7-25 |
Contract Programming | 7-26 |
Optimized mode | 7-27 |
__debug__ variable | 7-28 |
Error Handling | 7-29 |
The Python Debugger | 7-30 |
Python Debugger | 7-32 |
Debugging Example | 7-33 |
Python Debugger | 7-35 |
Profiling | 7-36 |
Profile Sample Output | 7-37 |
Summary | 7-38 |
8. Generators
Generators | 8-1 |
Iteration | 8-2 |
Iteration Everywhere | 8-3 |
Iteration: Protocol | 8-4 |
Customizing Iteration | 8-7 |
Generators | 8-8 |
Generator Functions | 8-9 |
Producers & Consumers | 8-13 |
Generator Pipelines | 8-14 |
Generator Expressions | 8-20 |
Why Use Generators? | 8-25 |
The itertools Module | 8-28 |
More Information | 8-29 |
9. Working with Text
Working With Text | 9-1 |
Overview | 9-2 |
Text Parsing | 9-3 |
Text Splitting | 9-4 |
Text Stripping | 9-5 |
Text Searching | 9-6 |
Text Replacement | 9-7 |
Commentary | 9-8 |
re Module | 9-10 |
re Usage | 9-13 |
re: Matching | 9-14 |
re: Searching | 9-15 |
re: Match Objects | 9-16 |
re: Groups | 9-17 |
re: Search Example | 9-19 |
re: Pattern Replacement | 9-20 |
re: Comments | 9-21 |
Generating Text | 9-23 |
String Concatenation | 9-24 |
String Joining | 9-25 |
String Joining Example | 9-26 |
Printing to a String | 9-27 |
String Interpolation | 9-28 |
Dictionary Formatting | 9-29 |
Template Strings | 9-30 |
Advanced Formatting | 9-31 |
Text Input/Output | 9-33 |
Line Handling | 9-34 |
Universal Newline | 9-36 |
Text Encoding | 9-38 |
International Characters | 9-39 |
Unicode | 9-40 |
Unicode Characters | 9-41 |
Unicode Charts | 9-42 |
Using Unicode Charts | 9-43 |
Unicode Representation | 9-45 |
Unicode I/O | 9-46 |
Unicode File I/O | 9-47 |
Unicode Encoding | 9-48 |
Encoding Errors | 9-49 |
Finding the Encoding | 9-52 |
Unicode Everywhere | 9-53 |
A Caution | 9-54 |
10. Binary Data Handling
Binary Data Handling and File I/O | 10-1 |
Introduction | 10-2 |
Overview | 10-3 |
Binary Data | 10-4 |
Common Scenarios | 10-5 |
Binary Data Representation | 10-6 |
Binary File I/O | 10-8 |
Binary Data Packing | 10-9 |
struct module | 10-10 |
struct Example | 10-13 |
Binary Type Objects | 10-15 |
ctypes library | 10-16 |
ctypes types | 10-17 |
ctypes structures | 10-19 |
Direct I/O | 10-20 |
Commentary | 10-21 |
11. Python Integration Primer
Python Integration Primer | 11-1 |
Python Integration | 11-2 |
Overview | 11-3 |
Subprocesses | 11-4 |
Simple Subprocesses | 11-5 |
subprocess Module | 11-6 |
Executing Commands | 11-7 |
Specifying the Command | 11-8 |
Capturing Output | 11-9 |
Sending/Receiving Data | 11-10 |
I/O Redirection | 11-12 |
Collecting Status Codes | 11-13 |
Polling a Subprocess | 11-15 |
Killing a Subprocess | 11-16 |
Data Interchange | 11-18 |
XML Overview | 11-19 |
XML Example | 11-20 |
XML Parsing | 11-21 |
etree Parsing | 11-22 |
Obtaining Elements | 11-23 |
Iterating over Elements | 11-24 |
Element Attributes | 11-25 |
Network Programming | 11-27 |
Low-level Sockets | 11-28 |
A Simple Web Server | 11-29 |
XML-RPC | 11-30 |
Simple XML-RPC | 11-31 |
ctypes Module | 11-34 |
ctypes Example | 11-35 |
ctypes Caution | 11-37 |
ctypes Types | 11-38 |
ctypes Cautions | 11-40 |
ctypes and C++ | 11-41 |
Extension Commentary | 11-42 |
COM Extensions | 11-44 |
Pythonwin and COM | 11-45 |
Disclaimer | 11-46 |
Python COM Client | 11-47 |
Python as a client | 11-48 |
Using a COM object | 11-49 |
Sample Output | 11-50 |
Commentary | 11-51 |
Jython | 11-52 |
Jython Example | 11-53 |
IronPython | 11-56 |
IronPython Example | 11-57 |
Commentary | 11-59 |
12. A Few Advanced Topics
A Few Advanced Topics | 12-1 |
Overview | 12-2 |
Variable Arguments | 12-3 |
Variable Keyword Use | 12-6 |
Variable Arguments | 12-7 |
Passing Tuples and Dicts | 12-8 |
List Sorting Revisited | 12-10 |
List Sorting | 12-11 |
Callback Functions | 12-13 |
Anonymous Functions | 12-14 |
Using lambda | 12-15 |
lambda and map() | 12-16 |
Advice on Lambda | 12-17 |
Delayed Evaluation | 12-19 |
Closures | 12-20 |
Using Closures | 12-23 |
Function Decorators | 12-25 |
An Example | 12-26 |
A Variation | 12-28 |
Decorators | 12-29 |
Why? Why?! WHY!?! | 12-30 |
Using Decorators | 12-31 |
Scenario: Error Handling | 12-32 |
Commentary | 12-34 |
A Decorator Solution | 12-35 |
Observe | 12-37 |
Commentary | 12-38 |
Decorated Methods | 12-40 |
Static Methods | 12-41 |
Using Static Methods | 12-42 |
Class Methods | 12-43 |
Using Class Methods | 12-44 |
Properties | 12-46 |
Advanced Properties | 12-47 |
Packages | 12-49 |
Creating a Package | 12-50 |
Using a Package | 12-52 |
__init__.py files | 12-53 |
Package Issues | 12-54 |
That's All Folks! | 12-56 |
Advanced Topics | 12-57 |
Shameless Plug | 12-58 |
|