[Tutor] btree problems

Bruce Sass Bruce Sass <bsass@freenet.edmonton.ab.ca>
Wed, 15 Mar 2000 12:57:01 -0700 (MST)


On Mon, 13 Mar 2000, Hans Nowak wrote:
> Well, at a quick glance... The tree object does not have an attribute 
> 'entry'. The node does, but not the tree, so tree.entry obviously will not 
> work. Maybe tree.tree.entry will (I did not verify this though).

Using "tree.tree.entry" results in "tree.insert(n)" failing with
"TypeError: too many arguments; expected 3, got 4" at
"self._InsertTree(self, self.tree, newnode)".  I've had a similar error
from a different route;  I'm sure when I figure out how I generated it
again I'll be able to figure out what went wrong that time (a two
equations, one unknown problem <he thinks with optimism> ;)... thanks.

I'm not sure where my head was at when I let that obvious error slip by
(couldn't see the forest for the trees, perhaps... sorry, couldn't
resist the pun).

I fixed that error in a hurry, only to run up against the one that was
the real problem (but it didn't spit out any error messages, which is
why I started thrashing around, got flustered, and sent a less than
ideal example to the list, sorry 'bout that). 

What confused me was the Tutorial's statements that Python doesn't need
the two kinds of parameters like Pascal, and that passing an object was
cheap because only a pointer was passed... I figured that passing an
object was equivalent to Pascal's "var variable:type" parameters.

Thanks for your help with that... perhaps you can also help with this:

I tried to get rid of the (uhm) header functions (the "def insert..." in
the example I sent) by doing:
	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?
i.e.,
	class btree:
		def __init__(self):
			self.tree = None
		def Insert(self, newnode, branch=self.tree):
		...
fails.

I was not too surprised that this,
	class btree:
		self.tree = None
		def Insert(self, newnode, branch=self.tree):
		...
failed at "self.tree = None", because there is no object called "self"
in the scope of the btree class.

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?


later,

	Bruce