Pastebin launched a little side project called HostCabi.net, check it out ;-)Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 12th, 2013  |  syntax: Python  |  size: 0.21 KB  |  hits: 62  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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