Classes in Python

laotseu bdesth at
Sat Apr 19 01:44:13 CEST 2003

Bill Martin wrote:
> I'm wondering about the value of allowing a class definition like this:
>             class C:
>               pass
> Now I can define a = c() and b = c(), then say a.x1 = 1.2, b.x2 = 3.5 or 
> some such. If I try to print a.x2 or b.x1, I get an exception message 
> basically saying those member variables don't exist. It seems to me this 
> defeats one of the basic ideas behind OOP, that is to assign members to 
> the class definition, thus ensuring that all instantiations of a class 
> have the same member variables and methods. I know there must be a 
> reason that python allows this kind of thing that I described, but I 
> can't figure out what that reason could be. To me, it looks like a very 
> dangerous thing to do. Can someone help me understand why we'd like to 
> do it? Thanks,

Why we'd like to do it? Well, it seems that some peoples would like to 
do it and need a whole lot of extra work for the same result. It's 
called the Decorator pattern.


More information about the Python-list mailing list