python __dict__

d = {'name':'aaa','age':12}it

class A(object):class

    def __init__(self,d):object

        self.name = d['name']date

        self.age = d['age']dict

等價於:di

class A(object):

    def __init__(self,d):

        self.__dict__.update(d)

相關文章
相關標籤/搜索