# Practical Python Programming - Instructor Notes Author: David Beazley ## Overview This document provides some general notes and advice on teaching the content of my “Practical Python” course including objectives, target audience, tricky bits, etc. These instructions were given to people teaching the course in a typical three-day corporate training environment. They might give you some insight about teaching your own course. ## Target Audience and General Approach This course is intended to be an “Introduction to Python” course for people who already have some programming experience. This is definitely not a course designed to teach people “programming 101.” Having said that, I have observed that the typical student in a Python course is also not likely to be a hard-core software engineer or programmer. Instead, you are probably going to get a mix of engineers, scientists, web programmers, and more inexperienced developers. Student background varies widely. You might have some students with a lot of C,C++, Java experience, others might know PHP and HTML, others may be coming from tools like MATLAB, and others still might have almost no traditional “programming” experience at all despite my best attempts to make the prerequisites clear. With this in mind, the course aims to teach Python through the general problem of manipulating data (stock market data in particular). This domain has been chosen because it’s simple and something everyone should know about it regardless of their background. Just as an example, students with weak programming skills are still likely to know about common things like using a spreadsheet (e.g., Excel). So, if they’re really stuck, you can tell them things like “well, this list of tuples is kind of like rows of data in a spreadsheet” or “a list comprehension is the same idea as applying an operation to a spreadsheet column and putting the result in a different column.” The key idea is to stay grounded in a real-world setting as opposed to getting sidetracked into esoteric “computer science” problems (e.g., “let’s go compute fibonacci numbers.”). This problem domain also works well for introducing other programming topics. For example, scientists/engineers might want to know about data analysis or plotting. So, you can show them how to make a plot using matplotlib. Web programmers might want to know how to present stock market data on a web-page. So, you can talk about template engines. Syadmins might want to do something with log files. So, you can point them at a log file of real-time streaming stock data. Software engineers might want to know about design. So, you can have them look at ways to encapsulate stock data inside an object or making a program extensible (e.g., how would make this program produce output in 10 different table formats). You get the idea. ## Presentation Guidelines The presentation slides (notes) are there to provide a narrative structure to the course and for reference by students when they work on exercises. Do not laboriously go over every bullet point on every slide--assume that students can read and that they will have time to go back when coding. I tend to go through the slides at a pretty brisk pace, showing short examples interactively as I go. I often skip slides entirely in favor of live demos. For example, you don't really need to do a bunch of slides on lists. Just go to the interpreter and do some list examples live instead. Rule of thumb: No more than 1 minute per slide unless it’s something unusually tricky. Honestly, you could probably skip most of the slides and simply lecture using live demos if you feel that it works for you. I often do this. ## Course Exercises The course has about 130 hands-on exercises. If you do every single exercise and give students time to think and code, it will likely take them about 10-12 hours. In practice, you will probably find that students require more time on certain exercises. I have some notes about this below. You should repeatedly emphasize to students that solution code is available and that it is okay to look at it and copy it--especially due to time requirements. Prior to teaching the course, I would strongly advise that you go through and work every single course exercise so that there are no surprises. During course delivery, I usually work every single exercise from scratch, without looking at the solution, on my computer while the students also work. For this, I strongly advise you to have a printed copy of the exercises on hand that you can look at without having to pull it up on the computer screen (which is being projected). Near the end of the exercise time period, I will start discussing my solution code, emphasizes different bits on the screen and talking about them. If there are any potential problems with the solution (including design considerations), I’ll also talk about it. Emphasize to students that they may want to look at/copy solution code before going forward. ## Section 1: Introduction The major goal of this section is to get people started with the environment. This includes using the interactive shell and editing/run short programs. By the end of the section, students should be able to write short scripts that read data files and perform small calculations. They will know about numbers, strings, lists, and files. There will also be some exposure to functions, exceptions, and modules, but a lot of details will be missing. The first part of this course is often the longest because students are new to the tools and may have various problems getting things to work. It is absolutely critical that you go around the room and make sure that everyone can edit, run, and debug simple programs. Make sure Python is installed correctly. Make sure they have the course exercises downloaded. Make sure the internet works. Fix anything else that comes up. Timing: I aim to finish section 1 around lunch on the first day. ## Section 2 : Working with Data This section is probably the most important in the course. It covers the basics of data representation and manipulation including tuples, lists, dicts, and sets. Section 2.2 the most important. Give students as much time as they need to get exercises working within reason. Depending on audience, the exercises might last 45 minutes. In the middle of this exercise, I will often move forward to Section 2.3 (formatted printing) and give students more time to keep working. Together, Sections 2.2/2.3 might take an hour or more. Section 2.4 has people explore the use of enumerate(), and zip(). I consider these functions essential so don’t skimp on it. Section 2.5 introduces the collections module. There is a LOT that could be said about collections, but it won't be fully appreciated by students at this time. Approach