[Numpy-discussion] question about standalone small software and teaching

Christopher Barker Chris.Barker at noaa.gov
Thu Apr 5 12:18:40 EDT 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:

class A:
    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:

class A:
     def __init___(self, ...)
         self.x = 4

Even though it's more typing.

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

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

Chris.Barker at noaa.gov



More information about the NumPy-Discussion mailing list