This course leads the student from the basics of writing and running Python scripts to more advanced features such as file operations, regular expressions, working with binary data, and using the extensive functionality of Python modules. Extra emphasis is placed on features unique to Python, such as tuples, array slices, and output formatting.

This is a hands-on programming class. All concepts are reinforced by informal practice during the lecture followed by graduated lab exercises.

Python Programming is a practical introduction to a working programming language, not an academic overview of syntax and grammar. Students will immediately be able to use Python to complete tasks in the real world.

Note: This course can be taught for either Python 2.x or Python 3.x. Version-specific course materials and exercises will be provided.

Audience: This course is appropriate for advanced users, system administrators and web site administrators who want to use Python to support their server installations, as well as anyone else who want to automate or simplify common tasks with the use of Python scripts.
Course Duration: 4 days
Prerequisites:

Students should already have a working, user-level knowledge of Unix/Linux, Mac, or Windows. While not required, basic skills with at least one other programming language will be helpful.

Hardware and Software Requirements:
  • LCD Projector connected to PC running any version of Windows Software
  • Python 2.6 or later (including 3.x)
    • Available from http://www.python.org or http://www.activestate.com/Products/ActivePython/
  • A text editor or IDE (Komodo Edit recommended)

Note: Detailed setup instructions will be provided

Course Objectives:
  • Create working Python scripts following best practices
  • Use python data types appropriately
  • Read and write files with both text and binary data
  • Search and replace text with regular expressions
  • Get familiar with the standard library and its work-saving modules
  • Know when to use collections such as lists, dictionaries, and sets
  • Understand Pythonic features such as comprehensions and iterators
  • Write robust code using exception handling
Course Outline:
  • An overview of Python
    • What is python?
    • Python Timeline
    • Advantages/Disadvantages of Python
    • Getting help with pydoc

 

  • The Python Environment
    • Starting Python
    • Using the interpreter
    • Running a Python script
    • Python scripts on Unix/Windows
    • Editors and IDEs

 

  • Getting Started
    • Using variables
    • Built-in functions
    • Strings
    • Numbers
    • Converting among types
    • Writing to the screen
    • Command line parameters

 

  • Flow Control
    • About flow control
    • White space
    • Conditional expressions
    • Relational and Boolean operators
    • While loops
    • Alternate loop exits

 

  • Sequences
    • About sequences
    • Lists and list methods
    • Tuples
    • Indexing and slicing
    • Iterating through a sequence
    • Sequence functions,keywords, and operators
    • List comprehensions
    • Nested sequences

 

  • Working with files
    • File overview
    • Opening a text file
    • Reading a text file
    • Writing to a text file
    • Raw (binary) data

 

  • Dictionaries and Sets
    • About dictionaries
    • Creating dictionaries
    • Iterating through a dictionary
    • About sets
    • Creating sets
    • Working with sets

 

  • Functions
    • About sequences
    • Function parameters
    • Global variables
    • Global scope
    • Returning values
    • Creating a library of functions

 

  • Sorting
    • The sorted() function
    • Alternate keys
    • Lambda functions
    • Sorting collections
    • Using operator.itemgetter()
    • Reverse sorting

 

  • Errors and Exception Handling
    • Syntax errors
    • Exceptions
    • Using try/catch/else/finally
    • Handling multiple exceptions
    • Ignoring exceptions

 

  • Using Modules
    • The import statement
    • Module search path
    • Zipped libraries
    • Creating Modules
    • Function and Module aliases

 

  • Regular Expressions
    • RE syntax overview
    • Basic patterns
    • RE Objects
    • Searching and matching
    • Compilation flags
    • Grouping
    • Replacing text
    • Splitting a string

 

  • Using the Standard Library
    • The sys module
    • Launching external programs
    • Walking directory trees
    • Grabbing web pages
    • Sending e-mail
    • Paths, directories, and filenames
    • Math functions
    • Random numbers
    • Dates and times
    • Zipped archives

 

  • An Introduction to Python classes
    • About o-o programming
    • Defining classes
    • Constructors
    • Instance methods
    • Instance data
    • Class methods and data
    • Destructors