2013年10月15日

摘要: 了解装饰器,要先了解闭包。1,闭包(closure)闭包是Python所支持的一种特性,它让在非global scope定义的函数可以引用其外围空间中的变量,这些外围空间中被引用的变量叫做这个函数的环境变量。环境变量和这个非全局函数一起构成了闭包。 1 def outer(x): 2 y = [1,2,3] 3 def inner(): 4 print x 5 print y 6 return inner 7 8 x = 5 #这个x没有被引用 9 f = outer(2)10 f()11 print f.__closure__ ... 阅读全文
posted @ 2013-10-15 16:34 小宇2 阅读(7621) 评论(2) 推荐(3) 编辑

导航