class settings:
def __init__(self,leds): for i in leds:
#print(i,leds[i])
self.i = leds[i]
leds={'redb':4,'gerd':27,'yelb':29}
s=settings(leds)我是想把leds這個字典傳入這個構(gòu)造函數(shù),然后直接用遞歸生成,但是這樣寫是報錯的,有什么好辦法把這種類型的字典,根據(jù)item和對應(yīng)的值直接構(gòu)造函數(shù)的簡便方法么?
1 回答

開滿天機(jī)
TA貢獻(xiàn)1786條經(jīng)驗 獲得超13個贊
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)
添加回答
舉報
0/150
提交
取消