learn OOP with Python

Terry Reedy tjreedy at home.com
Thu Oct 25 12:29:56 EDT 2001


"Achim Domma" <achim.domma at syynx.de> wrote in message
news:9r97co$cme$07$1 at news.t-online.com...
> Hi,
>
> a new employee will write scripts for us in python, but he has not
much
> experience with OOP. Are there any books that teach OOP concepts
using
> Python ? Is there a good source to give somebody with experiences in
Pascal
> and VBScript an introduction in the OO way of thinking ?
>
> greetings
> Achim

Great!  In my experience, Python is a good language for really
learning *and* appreciating OO concepts.  (C++ had about convinced me
that they were too much trouble.)  It incorporates OO thinking and
facilitates OO programming without encouraging OO fetishism.

I learned much from contemplating the type.method system (as in lists
and dictionaries)  and reading many examples of class definitions --
some in standard libraries, some posted on c.l.p and web sites.
Perhaps your employee can too.  To me, there are two basic concepts:

1. Package together related data and functions.  Functional
programmers do this with closures.  However, more programmers find
classes with attributes and methods a better (easier to use)
implementation of the idea.

2. Reuse code by extending and over-riding the methods (and
attributes) of inherited base classes.  This replaces the older method
of cut, paste, and edit.

Worth noting: the balance between data and function can vary from
mostly (or even all) data to mostly (or even all) function.  For
instance, consider DOM versus SAX processing of XML files.  (see
http://www.ora.com/catalog/pythonxml/chapter/ch01.html for a
user-viewpoint explanation and the xml part of the library for the
implementing code.)  A DOM instance swallows up an entire xml file,
however large, and exposes it as a tree structure with methods for
accessing the nodes (and their values) in random order.  A
SAX-derivative instance takes a handle to an xml file, serially scans
and parses the file with its core methods, and passes pieces to
user-defined methods added to the derivative class.

Though I did not answer your question about books, I hope your
employee might find these comments a bit of help.

Terry J. Reedy






More information about the Python-list mailing list