My question is probably easiest to see in code. I would like to do the following
class A():
def __init__(self, i):
self.i = i
if i > 0:
self.a = A(i-1)
The idea is that I want to create a class of type A that can recursively call its own constructor. If I code the above and attempt to create an instance of A I get the following:
a = Test(3)
---> self.a = A(i-1)
NameError: global name 'A' is not defined
Is it possible to have a class that recursively calls its own constructor? If so, how is it done?