其他分享
首页 > 其他分享> > Accessing the attributes by function getattr() and putting into the OrderedDict()

Accessing the attributes by function getattr() and putting into the OrderedDict()

作者:互联网

from collections import OrderedDict


del_attr = ["function", "module"]

def parse_config(cfg_module):

args = [ i for i in dir(cfg_module) if not i.startswith("__")]

config = OrderedDict()
for arg in args:
k = arg
v = getattr(cfg_module, arg)

import pdb
pdb.set_trace()

if type(v).__name__ in del_attr and k != "device":
continue
else:
config[k] = v


return config

标签:function,__,Accessing,OrderedDict,cfg,module,arg,config
来源: https://www.cnblogs.com/leifzhang/p/16182865.html