@@ -0,0 +1,2090 @@
+# Copyright (c) 2014 ASMlover. All rights reserved.%0A#%0A# Redistribution and use in source and binary forms, with or without%0A# modification, are permitted provided that the following conditions%0A# are met:%0A#%0A#  * Redistributions of source code must retain the above copyright%0A#    notice, this list ofconditions and the following disclaimer.%0A#%0A#  * Redistributions in binary form must reproduce the above copyright%0A#    notice, this list of conditions and the following disclaimer in%0A#    the documentation and/or other materialsprovided with the%0A#    distribution.%0A#%0A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS%0A# %22AS IS%22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT%0A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS%0A# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE%0A# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,%0A# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,%0A# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;%0A# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER%0A# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT%0A# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN%0A# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE%0A# POSSIBILITY OF SUCH DAMAGE.%0A#%0A#!/usr/bin/env python%0A# -*- encoding: utf-8 -*-%0A%0AOUTPUT = '%3Cint %25r, id = %25#0X, val = %25d%3E'%0Aw = x = y = z = 1%0A%0Adef f1():%0A  x = y = z = 2%0A%0A  def f2():%0A    y = z = 3%0A  %0A    def f3():%0A      z = 4%0A      print OUTPUT %25 ('w', id(w), w)%0A      print OUTPUT %25 ('x', id(x), x)%0A      print OUTPUT %25 ('y', id(y), y)%0A      print OUTPUT %25 ('z', id(z), z)%0A  %0A    clo = f3.func_closure%0A    if clo:%0A      print %22f3 closure vars:%22, %5Bstr(c) for c in clo%5D%0A    else:%0A      print %22no f3 closure vars%22%0A    f3()%0A  %0A  clo = f2.func_closure%0A  if clo:%0A    print %22f2 closure vars:%22, %5Bstr(c) for c in clo%5D%0A  else:%0A    print %22no f2 closure vars%22%0A  f2()%0A%0A%0Aclo = f1.func_closure%0Aif clo:%0A  print 'f1 closure vars:', %5Bstr(c) for c in clo%5D%0Aelse:%0A  print %22no f1 closure vars%22%0Af1()%0A

add demo for function closure