[Tutor] How to teach Python

wesley chun wescpy at gmail.com
Sun Aug 13 12:19:56 CEST 2006


hi elaine,

welcome to Tutor.  this list is really for those learning
Python and/or programming, so i'm going to assume that your
question is directed to mainly tutors, but perhaps tutees
in reference to their experience in learning Python and how
it was/is taught to them.

if you want to address teachers and other educational
individuals, you should probably post to the EDU-SIG
mailing list  -- i'd recommend cross-posting there if you wish:

http://mail.python.org/mailman/listinfo/edu-sig


there have been so many good responses so far that i can
just say that you will see "as others have said" quite
often in my reply here.


> I am going to be teaching "Introduction to Python
> Programming" in the Fall at Foothill College in Los
> Altos Hills, CA.

that's great!  i am also a Python teacher professionally
and happen to live just 5 minutes away from the campus.
if you ever need a substitute and don't wish to cancel
class for any some reason, drop me a line.


> I have been teaching programming for 20 years now,
> including Java and C++ as of late.

i have been teaching since 1983... BASIC, C, and Python
are the programming languages i have taught over the years.


> 1) Programming Style
>          while 1:
>               x = next()
>               if not x: break
>
> I have never allowed students to use break or continue
> in any programming class I have taught. I think of this
> type of code as belonging with the dreaded GOTO.
>
> I have always thought of break and continue as hacks that
> are not compatible with structured programming techniques.
> The only exception is using break in a switch in C, C++ and
> Java.
>
> However, all Python books seem to contain sample
> programs like this one. Do you think that code like
> this is desirable?

as others have mentioned already, because assignments are
not expressions in Python, it is quite a common idiom and
should be covered and implemented in this manner to keep
the code cleaner and more consistent.  remember that
"readability counts."  its are in all the books because
it is one of those basic idioms that ppl *have* to use
to get things done.

also as others have said, GOTO does not have the stigma
that it once had and that there is nothing wrong in
principle with break and continue when used with loops,
which is what they were designed to do.  you pretty much
have to be a very experienced programmer in order to know
when and where are the right places for that beast.

with that said, it would be a good idea to review the Zen
to truly understand the philosophy of Python.  it is one
thing teaching and learning Python, but it is another
step when you are able to understand it and program in a
"Pythonic" way.  (if away from the internet or a book,
you can access then Zen using 'import this' or 'python
-m this' from the shell.)


> 2) Since this is an introductory class, I am tempted
> to leave out "optional" topics like argument matching
> modes, walk, map, filter, reduce, apply. Do you think
> these are required for any Python programmer?

list comprehensions (and generator expressions) have obsoleted
map() and filter() because in general, their performance is
better, but that is not always the case.  apply() was
deprecated by the new function invocation mechanism using *
and ** back in Python 1.6.

reduce() will stick around.  i'm not sure what "walk" is, and
argument matching is important.  in fact, you need to cover
standard/formal/required argus, default args, keyword args,
and variable args (* tuples and ** dictionaries).


> 3) I need to teach a GUI in this class. I would like
> something that is easy, standard, and multi-platform.
> I am considering Tkinter and Jython. Any opnions on
> this?

Tkinter was chosen as the default for Python way back in the
early days because that was easy to understand and teach and
was available on the big 3 platforms (Unix, Win, Mac).  i
teach this in my courses (and also in "Core Python," the
textbook i wrote for college-level courses as well as for
working professionals), but also try to cover more advanced
and related widget sets like Pmw and Tix.  if you want to
teach the most basic concepts, even leaving off event-driven
programming, take a look at EasyGUI.

since then, however, it is no longer the only GUI toolkit.
wxWindows (and its adapter wxPython) has grown in userbase
quite a lot in the last few years -- it is also cross-plat-
form.  one of its greatst features is that it uses a system's
native widget set.  in other words, GUIs written on Win32
look like Windoze apps, and the same for Mac and *ix.

there are some nice "intro" libraries like PythonCard.  for
building GUIs in wxPython, one of the most painless ways is
using Boa Constructor.  you can drag-n-drop widgets onto a
canvas.  Boa writes the boilerplate code, and you only have
to worry about supplying the callbacks.

fwiw, i teach both an "Introduction to Programming using
Python" course as well as an (intensive) "Introduction to
Python" programming course.  the first is meant for those
with no programming experience whatsoever while the second
matches your prerequisite of knowledge of at least one other
high-level language is required. if you're curious as to
the topics i cover in either course, here are their course
descriptions, repsectively:

http://roadkill.com/~wesc/cyberweb/ippdsc.html
http://roadkill.com/~wesc/cyberweb/pp1dsc.html

it is also not by coincidence that the syllabus follows the
text and exercises found in "Core Python" very closely. :-)

good luck!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list