Python evangelists unite!

Delaney, Timothy tdelaney at avaya.com
Thu Nov 29 18:02:24 EST 2001


> From: brucehapman at hotmail.com [mailto:brucehapman at hotmail.com]
>
> So, I need some help. I've checked out c.l.p and some on-line
> articles, and I just can't find good practicle examples of a program
> that adds members to instances (or classes) at runtime. Anybody got
> any? I don't want to have to start avoiding my friend....

Suggest he look at unit tests. With unit testing, you are supposed to write
the tests first, then the code.

Unfortunately, in most languages, this is simply not possible. For example,
you can't compile the unit tests for a java package if you don't have at
least a bare skeleton of each class existing (all methods present, etc).

OTOH, this is incredibly simple in Python. The method doesn't exist yet?
Throw an exception! The class doesn't exist? Throw an exception! Which is
exactly what you want in a unit test - you can code one bit at a time, and
gradually your tests start succeeding.

Tim Delaney




More information about the Python-list mailing list