我在课堂上创建了一个函数,该函数在循环中添加一个新的对key:value到字典中。
def addFeature(self, *keys):
for key in keys:
print("key: {} \n".format(key))
self.content[self.counter1].update(key)
我是如何使用此功能的:
self.addFeature(
{'view': self.dict_of_views['view{}'.format(self.counter2)]},
{'link': self.p.pr_link(self.content[self.counter1]['id'])})
它有效。但是当我尝试调用在此循环函数中创建的键时遇到了一个问题:
self.addFeature(
{'view': self.dict_of_views['view{}'.format(self.counter2)]},
{'link': self.p.pr_link(self.content[self.counter1]['id'])},
{'nsnManagerID': self.ldap.ldap_searching(self.content[self.counter1]['author'])[1]},
{'nsnManagerEmail': self.ldap.ldap_searching(self.content[self.counter1]['nsnManagerID'])}
似乎因为这样做,我无法调用“ nsnManagerID”来获取“ nsnManagerEmail”:
self.addFeature(
{'view': self.dict_of_views['view{}'.format(self.counter2)]},
{'link': self.p.pr_link(self.content[self.counter1]['id'])},
{'nation': self.getNation(self.content[self.counter1]['author'])},
{'email': self.ldap.ldap_searching(self.content[self.counter1]['author'])[0]},
{'nsnManagerID': self.ldap.ldap_searching(self.content[self.counter1]['author'])[1]},
)
self.addFeature({'nsnManagerEmail': self.ldap.ldap_searching(self.content[self.counter1]['nsnManagerID'])})
然后它起作用了... 您能以正确的方式帮助我吗? 就像我在第三段代码中所示。