LostLin LostLin - 5 months ago 12
Python Question

recursion within a class

I am trying to place a recursive formula inside a class statement

class SomeNode:

def __init__(self, a):
leng = len(a)
half= leng/2
self.firstnode=a[0][0]
self.child1=SomeNode([a[i]for k in range(leng)])
self.child2=SomeNode([a[j] for j in range(leng)])


def recursfunc(self):
print self.firstnode
recursfunc(self.child1)
recursfunc(self.child2)


However I keep getting the error message NameError: global name 'recursfunc' is not defined

AJ. AJ.
Answer

You need to use self.recursfunc()