Creating attribute names from dict keys using var()
我正在使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | class DerivedProf(Prof): def __init__(self,profiel, TAG, code_DB): Prof.__init__(self, profiel, TAG) self.CountCodes(self.attr, code_DB) def CountCodes(self, attr, code_DB): count = 0 for key, value in code_DB.iteritems(): if value[0].lower() == 'true': for i,p in enumerate(attr): if int(attr[i].code2) == value[1]: count += 1 else: continue vars(self)[key] = count code_DB = {'code_72': ['true',72], 'code_74': ['true',74], 'code_76': ['true',76], 'code_88': ['true',88]} |
也许你在找