Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Closure example

By: a guest on Dec 2nd, 2012  |  syntax: Python  |  size: 0.15 KB  |  hits: 30  |  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. computed = False
  2.  
  3. def get_value():
  4.     global value
  5.     if not computed:
  6.         value = compute_value()
  7.         computed = true
  8.     return value