SHARE
TWEET

Untitled

a guest Jan 12th, 2013 63 Never
  1. class Obj(object):
  2.     def __init__(self):
  3.         pass
  4.  
  5. objs = [Obj(), Obj()]
  6. nums = [1,2]
  7.  
  8. for i in range(2):
  9.     objs[i].func = lambda x: nums[i]
  10.  
  11. assert ([objs[k].func(0) for k in range(2)]) == nums
RAW Paste Data
Top