Python中dict转为object

来源:互联网 发布:mysql获取union条数 编辑:程序博客网 时间:2024/05/01 13:56

openstack dashboard中前端的数据渲染要求数据格式居然是object,让我改了好久,默默的记下来,感谢 stackoverflow

stackoverflow原文内容:Convert Python dict to object?

我写的部分:

class Struct:    def __init__(self, **entries):        self.__dict__.update(entries)def _dict_to_object(policys):    policys_length = len(policys['policys'])    res = []    for i in range(policys_length):        policy = Struct(**policys['policys'][i])        res.append(policy)    print res    return res
0 0
原创粉丝点击