我有两个数据类,Route并且Factors. Route包含一个值和三个副本Factors。
Route不知道Factors包含多少个变量。我想获取这些变量的名称,然后获取Factors.
这是我目前拥有的:
@dataclass
class Factors:
do: bool # does it do the route
hub: int # how many of the locations are hubs
def __init__(self, do_init):
self.do = do_init
self.hub = 0 # will add later
def __str__(self):
return "%s" % self.do
@dataclass
class Route:
route: tuple
skyteam: Factors
star: Factors
oneworld: Factors
def __init__(self, route):
self.route = route.get('route')
# this could probably be done with …Run Code Online (Sandbox Code Playgroud)