[Tutor] btree problems
Wed, 15 Mar 2000 13:40:03 -0700 (MST)
On 15 Mar 2000, Justin Sheehy wrote:
> Bruce Sass <email@example.com> writes:
> > def Insert(self, newnode, branch=self.tree)
> > ...
> > but it fails, complaining about the "self" portion of the "self.tree"
> > object... Why can't the compiler see the self.tree in the __init__ a
> > few lines previous?
> Default parameters are computed when the function definition is
> evaluated. As this is before the object is instantiated, self.tree
> has not yet been created.
> > Am I being silly, expecting the compiler to look inside __init__?
> > After all, if __init__ exists, it will be run first thing whenever an
> > instance of a class is created, so it should be valid to reference stuff
> > in __init__ when defining methods of the class, right.
> > Is there a technical reason for the compiler not looking inside
> > __init__, or was it just an oversight that may be fixed in future
> > versions of Python?
> Since you can subclass a class and then override methods, one cannot
> guarantee that all of the methods of a given object will always be the
> same as when a given class was originally defined.
> It would be a drawback if the compiler were to treat __init__
> specially in this regard.
Hmmm, ok, sounds like a good technical reason... thanks, again.
Is Python a good first introduction to OOP, or does it have quirks that
will cause problems/confusion when I delve into C++?