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

Robert Kern robert.kern at gmail.com
Wed Apr 4 19:50:27 EDT 2007


Sebastian Haase wrote:
> Hello Gael,
> 
> Short question regarding your tutorial -- I'm very intrigued by traits
> and would like to use them too ....
> Why do you define e.g. the Point class like this:
> class Point(object):
>     """ 3D Point objects """
>     x = 0.
>     y = 0.
>     z = 0.
> 
> and not like this:
> class Point(object):
>     """ 3D Point objects """
>     def __init__(self):
>        self.x = 0.
>        self.y = 0.
>        self.z = 0.
> 
> I thought in the first case, if one did "a = Point(); a.x = 6"  that
> from then on ANY new point ( "b = Point()" ) would be created with b.x
> being 6 -- because 'x' is a class attribute   and nor a instance
> attribute  !?

No, setting "a.x = 6" will set it on the instance, not the class.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list