There are a few classes that I defined
class Animal:
def do_parent_method():
pass
class Monkey(Animal):
pass
class Elephant(Animal):
pass
@dataclass
class Zoo:
monkey: Monkey= Monkey()
elephant: Elephant = Elephant()
start_time: datetime = None
name: str = 'Not important at all'
def data_format(self):
items = [self.monkey, self.elephant] # Now I hard code here
for item in items:
do_something()
The key point is about how to get attributes in the Zoo
class
Maybe someday, we will add another animal in our code
@dataclass
class Zoo:
monkey: Monkey= Monkey()
elephant: Elephant = Elephant()
start_time: datetime = None
name: str = 'Not important at all'
def data_format(self):
items = [get the attributes that extends from Animal] # How to do?
for item in items:
do_parent_method()
For now I just want items
to be a list, so that I could for-loop it.
Or if you have another good idea is also good for me.
Note:
The all the attributes in Zoom class will only have some str, datetime, int type. All the other instance will be the children class of Animal class.
Fixed:
Accidentally entered 'zoo' into 'zoom'