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

Sebastian Haase seb.haase@gmx....
Wed Apr 4 20:53:52 CDT 2007


On 4/4/07, Robert Kern <robert.kern@gmail.com> wrote:
> 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.

OK, but what is "wrong" with the first way !?  I mean,  it somehow
seems not like "it's usually done" in Python ?  Normally there is
always a __init__(self) that sets up everything referring to self --
why is this tutorial doing it differently ?

-Sebastian


More information about the Numpy-discussion mailing list