"Phillip J. Eby" firstname.lastname@example.org wrote in message news:email@example.com...
At 01:39 PM 10/24/03 -0700, Zack Weinberg wrote:
class foo: A = 1 # these are class variables B = 2 C = 3
def __init__(self): self.a = 4 # these are instance variables self.b = 5 self.c = 6
I find this imperative syntax for declaring instance variables profoundly unintuitive. Further, on my first exposure to Python, I thought A, B, C were instance variables, although it wasn't hard to understand why they aren't.
A, B, and C *are* instance variables. Why do you think they aren't?
What? They are class attributes that live in the class dictionary, not the instance dictionary. They can be (directly) directly accessed as foo.A, etc, while foo.a, etc don't work. While they *may* serve as default or backup same-for-all-instances values for when there is no instance-specific value of the same name, that not the same, which is why they are defined differently. And a class attribute like number_of_instances would, conceptually, only be a class variable. Let's not confuse Zack further.
Terry J. Reedy