There is a list

b = ['car', 'Nissan xTtrail', '4', 'f1.jpeg', '2.5'] 

Classes defined:

 class CarBase: def __init__(self, car_type, brand, photo_file_name, carrying): self.car_type = car_type self.brand = brand self.photo_file_name = photo_file_name self.carrying = carrying` class Car(CarBase): def __init__(self, car_type, brand, passenger_seats_count, photo_file_name, carrying): super(Car, self).__init__(car_type, brand, photo_file_name, carrying) self.passenger_seats_count = passenger_seats_count` 

Tell me how to create an instance of the Car class using just the list b as attributes.

Those. if you call x = Car(b) , the interpreter will swear for the absence of the required brand arguments and so on.

1 answer 1

In case b = ['car', 'Nissan xTtrail', '4', 'f1.jpeg', '2.5'], use x = Car (* b)

It may be convenient for you to use the following dictionary: b = {'car_type': 'car', 'brand': 'Nissan xTtrail', 'passenger_seats_count': '4', 'photo_file_name': 'f1.jpeg', 'carrying ':' 2.5 '} Then you need to create an instance of the class like this: x = Car (** b)

PS In the latter case, the order of the elements is unimportant - when initialized, everything will "fall" as it should. (not to be confused with x = Car (* b)!)