动态初始化属性:常用于selenium,可以将定位的元素放到yaml中,然后取出来循环初始化属性
class dt_fz(): def __init__(self): _data = {"name": "zxb", "age": 18, "character": "hopeful"} for key in _data: self.__setattr__(key,_data.get(key)) #相对与self.name = "zxb" ,self."age"=18,self.character="hopeful" if __name__ == '__main__': print(dt_fz().name) #zxb print(dt_fz().age) #18 print(dt_fz().character) #hopeful