I have the following method definition in my class:
def show_values(self):
for node in self.Nodes:
nod = self.Nodes[node]
print self.M.nod.value
I receive the following error
File "nfg.py", line 30, in show_values
print self.M.nod.value
AttributeError: 'Model' object has no attribute 'nod'
I want to reach to self.M.(self.Nodes[node]).value, of course, but do not know
how. Can you help me?
Assuming
self.Nodes[node]is a string that you want to use for an attribute lookup, try the following:Note that
getattr(foo, 'bar')is equivalent tofoo.bar.If
self.Mis a dictionary or other mapping type and you want to do a key lookup, use the following: