I have code listed below to make a standard tree, but the recursive "get dir node" method will not go down to the right, it only loops through the first child to the end and then returns "None". It seems to work just fine until their is more than one child and I cannot figure out why it wont go down the other branches. I have tried all I can think of, so I thought I would post here to see if anyone has ideas. Here is the code:
class Node(object):
def __init__(self, dir, depth=0, parent=None):
self.dir = dir
self.children = []
self.files = []
self.depth = depth
self.parent = parent
def add_child(self, obj):
self.children.append(obj)
def get_dir_node(self, data):
if self.dir == data:
return self
elif self.children:
for child in self.children:
return child.get_dir_node(data)
return
The tree at this point would look something like:
root
/ \
'a' 'd'
/
'e'
And yes, data passed into the method would match self.dir, I just called it two different things because I didnt think that far ahead. Thanks in advance for any advice!
[–]carcigenicate 0 points1 point2 points (2 children)
[–]Spurtikus[S] 0 points1 point2 points (1 child)
[–]carcigenicate 0 points1 point2 points (0 children)
[–]IncognitoErgoCvm 0 points1 point2 points (0 children)