~dkuhlman/python-training-materials/Materials

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
.. vim: set ft=rst:

===========================
Python Training Materials
===========================

:author: Dave Kuhlman
:contact: dkuhlman@davekuhlman.org
:address:
    http://www.davekuhlman.org

:revision: 1.0b
:date: |date|

.. |date| date:: %B %d, %Y

: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.

.. sectnum::
.. contents::


Overview
==========

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".


How to use these Materials -- suggestions
-------------------------------------------

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.


Modifying documentation (HTML) files
--------------------------------------

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:

- Install Docutils, if you do not already have it.  You can find it
  here: http://docutils.sourceforge.net/

- Learn some reStructuredText, although in many cases, you may be
  able to simply follow the layout, format, and indentation of an
  existing document (a ``.txt`` file).  There is documentation at
  the Docutils site, and a quick reference is here:
  http://docutils.sourceforge.net/docs/user/rst/quickref.html

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.


Directory contents
====================

Here is a directory listing::

    Materials
    |-- Code_python                     # Code and exercises
    |   |-- Cmd
    |   |-- CommandLineOptions
    |   |-- ConfigParser
    |   |-- Database
    |   |-- Decorators
    |   |-- 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)


Materials/Docs
----------------

Documentation to be used during training.

- ``agenda_brief.html`` -- A brief overview of a possible schedule
  for a beginning course on Python programming.

- ``agenda_4day.html`` -- An overview and schedule for a 4 day
  course.

- ``outline_03.pdf`` -- Slides to be used to introduce (and in some
  cases, summarize) various topics.

- ``python_book_01.html`` and ``python_book_01.pdf`` -- A Python
  course book.  Also available at http://www.lulu.com/shop/shop.ep
  and at my Web site http://www.davekuhlman.org.  You might consider
  printing this book as a hand-out to students, although I'm sure
  that there are better Python texts available.

- ``python_course_03.html`` -- The course notes that I use while
  teaching.  When I teach, I often have these open in a Web browser
  on my screen and in front of the students via an overhead
  projector.

- ``python_versions_01.txt`` -- During the first morning's
  introduction to Python, I show this on the screen while describing
  the different versions of Python.


Materials/Exercises_python
----------------------------

Exercises for various topics -- Solutions are in the ``Solutions``
sub-directory.  For example:

- ``numbers1.html`` -- Exercises on ints and floats.

- ``lists1.html`` -- Exercises for lists and tuples.

- ``strings1.html`` -- Exercises for strings.

- ``class_static_method.html`` --

- ``dictionaries1.html`` -- Exercises for dictionaries.

- ``files1.html`` -- Exercises on reading and writing text files.

- ``statements1.html`` -- Exercises for Python statements.

- ``functions1.html`` -- Exercises for defining and calling
  functions.

- ``classes1.html`` -- Exercises for object-oriented programming and
  implementing classes in Python.

 
Materials/Code_python
-----------------------

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 -- Implement a function that can be
  applied as a decorator to trace other functions.

- ``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:

  - CSV -- Comma separated values -- Read and print a report from a
    CSV file.

  - Count words -- Assignment is in words.html.  Sample data is in
    words.dat.  There are several solutions; words3.py is preferred.

  - Various other exercises for string processing and text file
    processing.

- ``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.


Materials/Samples_python
--------------------------

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.


History
=========

Version 1.0b -- 01/21/2015

- Updated Python docs to 2.7.9.

Version 1.0a -- Previous history from Bazaar/bzr commits:

- 23: Dave Kuhlman 2015-01-21 Updated Python docs to 2.7.9
- 22: Dave Kuhlman 2014-07-25 [merge] Merge from scrubjay after Training at Cisco, San Jose, 07/21/2014
- 21: Dave Kuhlman 2014-07-19 Before Cisco training week of 07/21/2014
- 20: Dave Kuhlman 2014-07-18 [merge] Merge from scrubjay after training at Cisco week of 7/14/14
- 19: Dave Kuhlman 2014-07-12 Prior to Cisco class on 07/14/2014 (2)
- 18: Dave Kuhlman 2014-07-12 Prior to Cisco class on 07/14/2014
- 17: Dave Kuhlman 2014-07-10 [merge] Interim update # 2 -- After merge from scrubjay.
- 16: Dave Kuhlman 2014-07-10 Interim update
- 15: Dave Kuhlman 2014-07-07 Replaced Python standard docs with latest (2.7.8).
- 14: Dave Kuhlman 2014-01-17 [merge] After Cisco training San Jose 01/13/2014
- 13: Dave Kuhlman 2014-01-10 Before Cisco class on 1/13/2014
- 12: Dave Kuhlman 2014-01-03 Prep for Cisco training on 01/13/2014
- 11: Dave Kuhlman 2013-12-27 Before merge to scrubjay
- 10: Dave Kuhlman 2013-12-16 Before merge to scrubjay
- 9: Dave Kuhlman 2013-12-06 [merge] Merge after Cisco training week of 12/02/2013
- 8: Dave Kuhlman 2013-12-06 Modifications before merge from scrubjay
- 7: Dave Kuhlman 2013-11-29 Commit for Cisco class on 12/2/13
- 6: Dave Kuhlman 2013-11-26 Interim commit
- 5: Dave Kuhlman 2013-11-22 Interim commit
- 4: Dave Kuhlman 2013-11-21 Interim commit
- 3: Dave Kuhlman 2013-11-20 Interim commit
- 2: Dave Kuhlman 2013-11-12 Updates to README.txt
- 1: Dave Kuhlman 2013-11-11 Initial commit