How to get/set class attributes in Python

Terry Hancock hancock at anansispaceworks.com
Tue Jun 14 06:40:51 CEST 2005


On Monday 13 June 2005 03:50 pm, Kalle Anke wrote:
> On Mon, 13 Jun 2005 20:41:48 +0200, Terry Hancock wrote
> (in article <mailman.391.1118687097.10512.python-list at python.org>):
> 
> > 1) Assume the variables are of a sensible type (not 
> > necessarily the one you expected, though), and provide
> > exception handling to catch the case where their interface
> > does not match what you expect.
> 
> The problem I have with this is that I might discover an error at runtime 
> instead of compile time, this means that I need to really exercise all 
> possible test cases to make sure that I've covered everything (which of 
> course is a good thing) but it would be easier to discover this at "compile 
> time".

The Python solution to this problem is called "unittest". It is
at least as easy to do unit testing in Python as it is to properly
handle type-checking in C or Java.

> > Let's face it -- should it matter if you "are a programmer" 
> > or only if you "can program"?  This is the difference in
> > philosophy behind a dynamically-typed language like
> > Python and a statically typed one like Java.
> 
> I don't really understand what you're meaning (English isn't my native 
> language as you probably already have discovered)

(Actually no, you're quite fluent, AFAICT).  I was making
an analogy:

Requiring a variable to be, say, a "float" is like insisting that
only people with the job title "Programmer" be allowed to
see the language documentation.

In both situations, real life will confront you with situations
where you will wish that you had been more tolerant.  Lots
of us are not "Programmers", but we do quite a bit of programming.

Likewise, you'll be happier to discover that ints or complex
numbers work with your code too, without having to jump
through hoops to make it happen.

I find the biggest problem coming to Python from a language
like C, C++, or Java is that you overthink things and try to
do them the hard way.  A lot of times, you find out that the
"Python way" to do the thing is so blindingly obvious that
it just didn't occur to you that it could be that simple.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list