def insert_left(self, new_node):
if self.left == None:
self.left = BinaryTree(new_node)
else:
t = BinaryTree(new_node)
t.left = self.left
self.left = t
def insert_right(self, new_node):
if self.right == None:
self.right = BinaryTree(new_node)
else:
t = BinaryTree(new_node)
t.right = self.right
self.right = t
def get_left(self):
return self.left
def get_right(self):
return self.right
def set_root(self, obj):
self.key = obj
def get_root(self):
return self.key
r = BinaryTree('a')
print "key of root is ", r.get_root()
print "left key of node is ", r.get_left()
r.insert_left('b')
print "now, left key of node is ", r.get_left()
print "what key of left root node is ", r.get_left().get_root()
r.insert_right('c')
print "right key of node is ", r.get_right()
print "what key of right root node is ", r.get_right().get_root()
r.get_right().set_root('hello')
print "has just inserted value is ", r.get_right().get_root()
r.tree_walk()
self.left.tree_walk()
AttributeError: 'NoneType' object has no attribute 'tree_walk'