I'm new to ptyhon I'm trying to do something that should be quite simple but I can't do it.
I have to create objects that will have a different number of attributes each time. For example :
OBJECT A
Attribute 1
Attribute 2
Attribute 3
OBJECT B
Attribute 1
Attribute 2
The attribute 1 will always be there (with different values but there will be at least one attribute in the object). I've created an example class :
class car():
def__init__(self, Color, **kwargs):
self.Color = Color
for key, value in kwargs.iteritems():
setattr(self, key, value)
So now I have to call the contructor, but as the number of attributes will be variable, how should I do it ?
CAR1_ATTRIBUTES = (Passengers = 5, Tires = 4)
CAR2_ATTRIBUTES = (DriverName = "John", Tires = 4, DoorsNumber = 5)
CAR3_ATTRIBUTES = (DriverName = "Tom", Velocimeter = "Y", DoorsNumber = 4)
CarsList = []
for i in range(0,3):
CarObject = Car("RED", RESTOFATTRIBUTES)
CarsList.append(CarObject)
"RESTOFATTRBUTES" will be variable (it could be one single argument or 1563...)