Author: | Dave Kuhlman |
---|---|
Contact: | dkuhlman@davekuhlman.org |
Address: | http://www.davekuhlman.org |
Revision: | 1.0b |
Date: | October 14, 2015 |
Copyright: | Copyright (c) 2013 Dave Kuhlman. All Rights Reserved. This software is subject to the provisions of the MIT License http://www.opensource.org/licenses/mit-license.php. Also see LICENSE.txt in this directory. |
---|---|
Abstract: | This document provides notes and guidance on the use of the materials in this directory for teaching a beginning class of Python programming. |
Contents
The contents of this archive/directory are intended to be used by an instructor delivering a course on beginning Python programming.
This README gives a brief survey of where to find things in this directory and its sub-directories and some guidance on how to use the materials.
Documentation -- Look in the Docs directory. A more detailed description of the contents of that directory is below.
Assignments and exercises -- In several directories you will find pairs of files: a text (.txt) file and an HTML file (.html). Usually, the HTML file was generated from the text file (the source) using Docutils (http://docutils.sourceforge.net/). Often these documents give assignments and exercises that an instructor can give to students to work on after the completion of a given topic. There is usually a solution (a Python module that solves the execercise), which you can show to students and discuss after they have had time to work on the exercise. Often the solution is "hidden" in a sub-directory named "Solutions".
I carry these materials to class on CDs and flash drives. On the morning of the first day of class, I ask students to copy this directory (Materials) onto their hard drive.
The latest version of these materials is available at my Web site: http://www.davekuhlman.org/#materials-for-python-training
I teach most of the course from the notes in Docs/python_course_03.html.
See section Directory contents for more detailed information on the contents.
Many of the HTML files were produced using Docutils, which is a documentation preparation system written in Python. These HTML files were generated from corresponding source text files containing reStructuredText. For example, the file "abc.txt" would be used to generate "abc.html".
To do this, you will need the following:
Once Docutils is installed on your machine, you should be able to re-generate an HTML file with the following:
$ rst2html.py --stylesheet=Docs/pytraining_docutils.css abc.txt abc.html
The --stylesheet option is not strictly necessary, but will produce output with an appearance more consistent with other HTML files in these Materials. The file pytraining_docutils.css is in the Docs/ directory, so you may need to adjust the above command depending on your current directory.
Here is a directory listing:
Materials |-- Code_python # Code and exercises | |-- Cmd | |-- CommandLineOptions | |-- ConfigParser | |-- Database | |-- Decorators | |-- DocServer | |-- ExceptionSubclass | |-- FixedLenRecords | |-- Import | |-- IteratorGenerator | |-- Jython | |-- Oop | | `-- Solutions | |-- TextAndFiles | |-- TreeStructure | |-- Unittest | | `-- Solutions | |-- VarialbeLenRecords | |-- WrapperEnvelopeIterable | |-- Xml | |-- Zipfiles | |-- package_sample1 | | `-- sub_package | `-- package_sample2 |-- Docs |-- Exercises_python # Exercises and assignments (see below) | `-- Solutions |-- Samples_python # Other samples of Python code |-- Templates_python # Starter templates for modules and scripts |-- Work # An empty directory for student work |-- bin # Files to set command line environment `-- python-2.7.6-docs-html # The Python standard documentation (HTML)
Documentation to be used during training.
Exercises for various topics -- Solutions are in the Solutions sub-directory. For example:
If you have extra time at the end of the last day of training, you may want to consider using one or more of the following as exercises. In most cases, each of the following directories contains a Solutions sub-directory containing sample solutions.
Cmd -- Exercise -- Implement an interactive prompt using the cmd module.
CommandLineOptions -- Exercise -- Parse and capture command line options using argparser and getopt.
ConfigParser -- Exercise -- Parse and write a .ini configuration file.
Database -- Exercise -- Create, write, and query/read a relational database using the sqlite3 module.
Decorators -- Exercise -- (1) Implement a function that can be applied as a decorator to trace other functions. (2) Implement a descriptor class and a class that uses and tests the descriptor.
DocServer -- Exercise -- (1) Implement module/library to provide access to a SQLite database containing documents. (2) Implement a ZeroMQ server and ZeroMQ client to access that document database using the above module/library. (3) Implement a command shell using cmd from the Python standard library to access the document database. (4) Implement a Web application using Pyramid to provide access to the document database.
A Python script which can be used to create an empty SQLite database for this project is in DocServer/create_doc_database.py.
Sample databases containing a few documents are in DocServer/Data.
The Anaconda distribution of Python (at http://continuum.io) comes with ZeroMQ for Python (zmq). I suggest that you have students install Anaconda in order for them to work on this DocServer project. To install Pyramid in your Anaconda installation, use:
$ conda install pyramid
Also see the problem description and notes in: Code_python/DocServer/docserver.html.
Import -- Sample -- Shows importing a module that imports a module, and demonstrates modifying a value that is global within a module.
IteratorGenerator -- Exercise -- Implement a generator function -- a function the contains yield and, therefore, returns a generator (an iterable).
Oop -- Exercise -- Implement a class hierarchy used to track and display a fleet of vehicles and their routes.
package_sample1 -- An example of a Python package that makes several objects global within the package. To get an idea of what it does, do the following from the directory immediately above it:
>>> import package_sample1 >>> print dir(package_sample1)
package_sample2 -- Similar to package_sample2.
TextAndFiles -- Exercises -- Specifically:
TreeStructure -- Exercise -- Create, walk, and display tree structures implemented with (1) lists, (2) dictionaries, and (3) instances of a custom class.
Unittest -- (1) Samples of unit test classes and harnesses to run those tests. (2) Exercise -- Implement a unit test class (sub-class of unittest.TestCase) and a test harness to test several database access functions.
Xml -- Exercise -- elementtree_walk.html for an exercise using xml.etree.ElementTree.
ExceptionSubclass -- Exercise -- Define an Exception subclass and catch it in a try:except: statement. A similar exercise is in Exercises_python/statements1.html.
FixedLenRecords -- Write and read fixed length records, specifically text records that are not separated by newlines.
VarialbeLenRecords -- Write and read variable length records, specifically text records that are not separated by newlines and where the record length is stored in the first bytes of each record.
WrapperEnvelopeIterable --
Zipfiles -- Exercise -- Create and process zip file archives using the zipfile module.
This directory contains samples of Python code. It's the place where I put sample files that I do not need immediately, but think that I might during some class in the future, and that I don't want to throw away.
When you need a sample of code to illustrate some Python topic and you can't find it in Exercises_python or Code_python, you might look for it here.