Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openstack 将类转化为字典 #4

Open
sfPPP opened this issue Mar 29, 2018 · 0 comments
Open

openstack 将类转化为字典 #4

sfPPP opened this issue Mar 29, 2018 · 0 comments

Comments

@sfPPP
Copy link
Owner

sfPPP commented Mar 29, 2018

第一个参数为类对象,第二个参数为属性的list
to_dict (object,attr_list):
obj = {}
for key in attr_list:
obj[key] = getattr(object, key, None)
return obj

比如要获取 cat 的eat ,color,size ,age ,long,weight等属性
attr_list = [eat ,color,size ,age ,long,weight]
调用方法为 to_dict(cat,attr_list)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant