0

I have a DataSet class which is a @dataclass and is defined here.

@dataclass
class DataSet:
    teams: list[Team]
    services: list[Service]
    functionalities: list[Functionality]

I want to be able to iterate over all the attributes in this DataSet class. Team, Service and Functionality are @Dataclass as well. For example, i've written some pseudocode here.

dataset_keys = ['services', 'teams', 'functionalities']
for key in dataset_keys:
    for i in src[key] <-- 'DataSet' object is not subscriptable

The only methods available on this object are the following. Found by running dir(src)

['__annotations__', '__class__', '__dataclass_fields__', '__dataclass_params__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'functionalities', 'services', 'teams']

How can I achieve my goal by being able to iterate over this set of keys?

petezurich
  • 7,683
  • 8
  • 34
  • 51
Trenton
  • 15
  • 4

0 Answers0