[Numpy-discussion] question about standalone small software and teaching
Thu Apr 5 11:18:40 CDT 2007
Gael Varoquaux wrote:
> I have recently
> started avoided using class attributes when not necessary,
I agree. I use class attributes when I need, well, class attributes.
That is an attribute that is shared by all the instances of the class.
In fact, in the example:
x = 4
A_instance = A()
A_instance.x = 10
A.x is NOT the class attribute, it is now an instance attribute, which
is found before the still existing class attribute A.x. Yes, the class
attribute can serve as a default, but, I think, in a situation when you
are intending the class attribute to be over-ridden by an instance
attribute, then it's clearer to define it as an instance attribute in
the first place:
def __init___(self, ...)
self.x = 4
Even though it's more typing.
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
More information about the Numpy-discussion