Python II: Applied Python
Private Training

Course Summary

This 4 day course picks up where Python I leaves off, covering some topics in more detail, and adding many new ones, with a focus on enterprise development. This is a hands-on programming class. All concepts are reinforced by informal practice during the lecture followed by lab exercises. Many labs build on earlier labs, which help students retain the earlier material.

Audience
Advanced users, system administrators and web site administrators who want to use Python to support their server installations, as well as anyone else who wants to automate or simplify common tasks with the use of Python scripts.
Course Length
4 Days
Prerequisites
All students should be able to write simple Python scripts, using basic data types, program structures, and the standard Python library.

Objectives

Leverage OS Services

Code graphical interfaces for applications

Create modules

Create and run unit tests

Define classes

Interact with network services

Query databases

Process XML data

Detailed Outline

  1. Python Refresher
    • Variables
    • Python Data Types
    • Sequences
    • Mapping types
    • Program Structure
    • Files and console I/O
    • Conditionals
    • Loops
    • Defining a Function
    • Function Parameters
    • Built-ins
  2. OS Services
    • The os module
    • Environment Variables
    • Launching External Programs
    • Paths, directories, and filenames
    • Walking Directory Trees
    • Dates and Times
    • The Time Module
    • The Calendar Module
  3. Pythonic Programming
    • Common Python Idioms
    • Slicing and Dicing
    • Unpacking Function Arguments
    • Lambda Functions
    • Nested Functions
    • List Comprehensions
    • Iterables
    • Generator Expressions
    • Writing Generators
    • Python Time Travel
    • Three Python Easter Eggs
    • A String Trick
    • String Formatting
  4. Modules and Packages
    • Modules
    • Using import
    • Initialization Code
    • Namespaces
    • Executing modules as scripts
    • Packages
    • Configuring Import with __init__.py
    • Name Resolution (AKA scope)
    • Nested Functions
    • Python Style
  5. Classes
    • About OO Programming
    • Defining Classes
    • Constructors
    • Instance Methods
    • Properties
    • Class Methods and Data
    • Static Methods
    • “Private” Methods
    • Inheritance
    • Untangling the Nomenclature
  6. Metaprogramming
    • Special Attributes
    • globals() and locals()
    • Working with Attributes
    • The inspect Module
    • Decorators
    • Decorator Functions
    • Decorator Classes
    • Decorating Classes
    • Creating Classes at Runtime
    • Monkey Patching
  7. Objectives
    • Program Development
    • Comments
    • pylint
    • Customizing pylint
    • Using pyreverse
    • The unittest module
    • Skipping Tests
    • Making a suite of tests
    • Automated test discovery
    • Using Nose
    • The Python debugger
    • Starting debug mode
    • Stepping through a Program
    • Setting Breakpoints
    • Profiling
  8. Distributing Modules
    • Installing Packages
    • Ways to distribute Code
    • Overview of distutils
    • Preparing for distribution
    • Creating a Source Distribution
    • Creating built distributions
    • setup.py options
    • setup.py commands
  9. Database Access
    • The DB API
    • Available Interfaces
    • Connecting to a Server
    • Creating a Cursor
    • Executing a Statement
    • Fetching Data
    • Parameterized Statements
    • Dictionary Cursors
    • Metadata
    • Transactions
    • Object-relational mappers
    • What is PyQt4?
    • Event Driven Applications
    • GUI Application Flow Chart
    • External Anatomy of a PyQt4 Application
    • Internal Anatomy of a pYQt4 Application
    • Using designer
    • Anatomy of a designer-based application
    • Naming Conventions
    • Common Widgets
    • Layouts
    • Selectable Buttons
    • Making your application stretch
    • Actions and Events
    • Menu bar
    • Status bar
    • Using predefined dialogs
    • Creating custom dialogs
    • Tabs
    • Niceties
    • Working with Images
    • Tkinter Overview
    • Basic Tkinter Programming
    • Object-oriented Tkinter
    • Widgets
    • Labels
    • Buttons
    • Setting Fonts
    • Colors
    • Standard Colors
    • Variable Wrappers
    • Selectable Buttons
    • Text entry blanks
    • Multiline text entry/display
    • Listbox
    • Arranging Widgets
    • Using pack()
    • Tweaking the layout
    • Frames
    • Adding Scrollbars
    • Callbacks
    • Callback Parameters
    • Binding Events
    • Event Specifications
    • Creating Menus
  10. Network Programming
    • Sockets
    • Socket Options
    • Client Concepts
    • Server Concepts
    • Application Protocols
    • Forking Servers
    • Grabbing HTML from the Web
    • Consuming Web Services
    • Web Data the Easier Way
    • Sending Email
    • Binary Data
    • The struct Module
  11. Multiprogramming
    • What are Threads?
    • The Python Thread Manager
    • The threading Module
    • Threads for the impatient
    • Creating a Thread Class
    • Variable Sharing
    • Using Queues
    • Debugging Threaded Programs
    • The Multiprocessing Module
    • Alternatives to Multiprogramming
  12. System Administration
    • The subprocess module
    • subprocess convenience functions
    • Using the sh module
    • Remote access
    • Other useful modules
    • Permissions
    • Saving Information
    • Creating a useful command line scripts
    • Creating Filters
    • Parsing the command line
    • Simple logging
    • Logging Levels
    • Formatting Log Entries
    • Logging to other Destinations
  13. XML and JSON
    • About XML
    • Normal approaches to XML
    • Which module to use?
    • Getting Started with ElementTree
    • How ElementTree works
    • Creating a new XML Document
    • Parsing an XML Document
    • Navigating the XML Document
    • Using XPath
    • About JSON
    • Reading JSON
    • Writing JSON
  14. Extending Python
    • Why extend Python?
    • Ways to extend Python with C
    • Hand-coded C
    • Overview
    • The C Program
    • Methods
    • The Method Table
    • The init function
    • Handling errors
    • Custom exception objects
    • Putting it all together
    • Using SWIG
    • The interface file
    • Generating the Wrappers
    • Building and installing the extension
    • cytpes