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
posted @ 2022-04-23 16:54  呦呦南山  阅读(16)  评论(0编辑  收藏  举报