I want to create a class that has the following structure:
ClassName
UpperLevel
Element_A:
val_1 = 'example'
Element_B: Tuple(str, str)
Element_C: Tuple(str, str)
LowerLevel
Element_D: Tuple(str, str)
Element_E: Tuple(str, str)
so that I can type: ClassName.UpperLevel. and the IDE will recommend me Element_A, Element_B, Element_C.
I have the following:
class Element:
def __init__(self, val_1, val_2):
self.val_1: str = val_1
self.val_2: str = val_2
class Example:
def __init__(self):
self.upper_level.Element_A = Element(r'example1', r'example2')
self.upper_level.Element_B = Element(r'example1', r'example2')
self.upper_level.Element_C = Element(r'example1', r'example2')
self.lower_level.Element_D = Element(r'example1', r'example2')
self.lower_level.Element_F = Element(r'example1', r'example2')
Note that the whole hierarchy is defined, meaning that I know all of the "levels" and "elements" beforehand, I do not need to create the dynamically in reality.
Why does this not work?
Do I need to have another class for Level?
To create a single
Levelclass with different properties you can useSimpleNamespace