Python动态创建类,python动态创建,#author: D.L


#author: D.Luciferdef create_object(object_attribute):    class o: pass    if '#class' in object_attribute.keys():        (module_name, class_name) = object_attribute['#class'].rsplit('.', 1)        module_meta = __import__(module_name)         class_meta = getattr(module_meta, class_name)         o = class_meta()    for k in object_attribute:        if str(type(object_attribute[k])) == '<class \'dict\'>':            setattr(o, k, create_object(object_attribute[k]))        else:            setattr(o, k, object_attribute[k])    return o

评论关闭