I am struggling with my code, specifically subclasses. I have a parent class that when initialized will call its subclass to be used as an attribute, in the form of a list of objects. I have seen numerous post where a person forgets to call the __init__() of the parent. My issue is different in that the parent is calling the child class and I do not want to call it.
I am getting the following error:
NameError: name 'bundle' is not defined
I am confused because it is clearly defined as the parent class. Any ideas?
class bundle(object):
"""Main object to hold graphical information"""
def __init__(self, size,nzone):
self.size = size
self.rows = math.sqrt(size)
self.cols = math.sqrt(size)
subchans = []
r = 1
c = 1
for i in range (1,self.size):
subchans.append(bundle.subbundle(r,c,self.rows,self.cols))
r += 1
if r > self.rows :
r = 1
c += 1
class subbundle(bundle):
""" Defines geometry to represent subbundle"""
def __init__(self, row, col, rows,cols):
bundleis not defined until after the class definition finishes, sosubbundlecannot inherit from it and be a nested class. It is not clear from the example why you would wantsubbundleto be either inherited or nested, though.bundleis, i think it would have to besubbundle(self)instead. But what you PROBABLY actually want is to makesubbundle(bundle)a class of its own, that is not nested