次の例では:
class A(object):
pass
prop1 = 1
prop2 = 2
prop3 = 3
prop4 = 4
obj = A()
tmp = ['prop1', 'prop2', 'prop3', 'prop4']
getter = [ lambda: getattr(obj, x) for x in tmp ]
4
を呼び出すと、常に取得していgetter
ます:
[getter[i]() for i in range(4)]
#[4, 4, 4, 4]
どうして!?