Classes in Python
Bill Martin
wcmartin at vnet.net
Fri Apr 18 11:32:43 EDT 2003
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,
Bill Martin
More information about the Python-list
mailing list