Python uses dictionary arguments to create constructors

class settings:
    def __init__(self,leds):
        for i in leds:
            -sharpprint(i,leds[i])
            self.i = leds[i]

leds={"redb":4,"gerd":27,"yelb":29}
s=settings(leds)

I want to pass the leds dictionary into this constructor and generate it recursively, but this is an error. Is there any easy way to construct a function directly based on item and corresponding values for this type of dictionary?

May.24,2021

The special methods of attribute management in

python are _ _ getattr__ , _ _ getattribute__ , _ _ setattr__ , _ _ delattr__ , _ _ dir__ , and so on. _ _ setattr__ literally knows that it can be used to bind properties to objects.

class settings:
    def __init__(self,leds):
        for i in leds:
            self.__dict__[i] = leds[i]

leds={'redb':4,'gerd':27,'yelb':29}
s=settings(leds)
Menu