Class Variable Question

David C. Ullrich ullrich at math.okstate.edu
Wed Apr 11 12:21:43 EDT 2001


On Wed, 11 Apr 2001 00:47:07 -0700, "Robert Johnson"
<rjohnson at exotic-eo.com> wrote:

>> It's not entirely clear to me whether you mean to be talking about
>> setting attributes of classes or attributes of class instances.
>
>I am talking about "creating" attributes in class instances (not setting).

Sorry - that was a typo, I understood you meant creating.

>I come from the C++ community where the definition of a class is separate
>from its implementation.  My ambiguous question and the variety of replies I
>received actually helped me to understand that in Python a Class Object is
>created the moment it is written

Or perhaps the moment the class definition is compiled.

> and is separate from the Object instance,
>which explains why some thought it strange that I would want to be able to
>block the adding of attributes, effectively blocking a simple form of
>inheritance.  In C++ the class object IS the instance and many C++
>programming books use the terms "Object" and "Instance" interchangeably.
>The splitting of Object and Instance is something that I did not catch in my
>readings of Python programming books.

Certain that someone will correct me if I'm wrong, sounds like you
haven't quite got the terminology yet. It's not a distinction between
"object" and "instance", those are more or less synonymous
everywhere. The distinction is between "class" and ["object" or
"instance"].

Ok, in Python it's not that simple because everything is an
object and not everything is an instance... then there's
the fact that a class itself _is_ an object. But you evidently
did mean to be asking about adding attributes to instances,
while what you actually asked about was adding to classes.
(My first guess was you actually meant "object", not "class" -
this is because I come from a place where "everybody" says
"class" when they mean "object".) The problem was ignoring
the distinction between "class" and "object".

I don't actually know any C++. But I didn't think that classes
were objects at all in C++. I certainly believe that C++ books
use "Object" and "Instance" interchangeably, but I hope
they do not use these two words interchangeably with
"class". They don't, so they? (If not that gives you an
excellent excuse: If classes are not objects then the
phrase "class object" must mean "instance of a class".
Alas here "class object" means "class".)

>I think this is the first question I have ever posed to a newsgroup that has
>generated such a large thread.
>
>Thanks for the reply,
>
>Robert Johnson
>
>




More information about the Python-list mailing list