I was looking for a long time how to pass an arbitrary number of arguments to __init__ . Here is the solution found:
class Thing: '''a class with a constructor (or other function) that takes a variable number of arguments and then sets them as class attributes conditionally. ''' def __init__(self, **kwargs): for key, value in kwargs.items(): setattr(self, key, value) door = Thing(size='180x70', color='red chestnut', material='oak') print(door.size, door.color, door.material, sep = ', ') house = Thing(height='23 m', doors=6, rooms=4, material='break') #180x70, red chestnut, oak print(house.height, house.doors, house.rooms, house.material, sep=', ') #23 m, 6, 4, break I am sure there is a solution shorter than 2 times, but I can not find it.
self.__dict__.update(kwargs). It's easier nowhere. - insolor