21.python中的闭包和装饰器

时间:2022-09-26 19:50:59

  python中的闭包从表现形式上定义(解释)为:如果在一个内部函数里,对在外部作用域(但不是在全局作用域)的变量进行引用,那么内部函数就被认为是闭包(closure)。

  以下说明主要针对 python2.7,其他版本可能存在差异。

  也许直接看定义并不太能明白,下面我们先来看一下什么叫做内部函数:

def wai_hanshu(canshu_1):

    def nei_hanshu(canshu_2):  # 我在函数内部有定义了一个函数
return canshu_1*canshu_2 return nei_hanshu # 我将内部函数返回出去 a = wai_hanshu(123) # 此时 canshu_1 = 123
print a
print a(321) # canshu_2 = 321

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXQAAAAnCAIAAACQbCTpAAADw0lEQVR4nO2c3ZXbIBBG1VXoJBWYPlJAqMY0syrFD8qDhPiZQci7wrGle88+6LB4YBB8DGAzTAAAHRj+dwUA4JwgLgDQBcQFALqAuABAFxAXAOjCd8VldGYYhmGw/tDqTN4ebvKbZXl7jH9H2QH4MPaLi7dxgIzOzMPlcC0Y3c2NRxr8SVlHefdKxQyqbzZcE3lCQlDBWRAXZK7UmbRbCDt50mJIqWFmBM7CTnEphsdho2V07o171TuKy3aLjc4sJXlbkxeRJxFZb4MshDqn88hiMfxrkaDVNd2OW9K89xs1fKX+wovYIy6xPwTebtQ9jDnf3/MtNjpj4vjW1aXM85XZXJ8TcTHuK/tUrT6157lUF7SlVsO6HMJn0haX4p0nYe4ya3mbPdzDLoNzJgt+i6g6C73VmTD91GymYnmakqG4XXpIUMuSrgs7uRN6WdGzZKpP8xQtptbhYUy5DJEtplU4Hd7hXRg3LlW9NyTAFA0kXcjL1sVOSFGMXzZKV2Yx+GSa4qL2ntoqKX2Yu+Waom7TSONFSuilsbdKy9OUiUut9DCuY69vxk3Szh5PVaeadkoexmh5mpvQMuc8ZNc1S9VarghF5LK6UORT6qMEOau2PPf24bPZsyxqdoLtsbcxig6xPE2KuCgSIOb8PeIiyoqWNuqzxgvPeZHyMEaU1axzbdER90tqedIcss73LKjYEghhZ05M9mU2lkUoy7k4ZEM33eGrDZ41ckm3JNcP+kpnVSOXb4hL0qfH8ZnIpeJO9EbJI5YA9YfYYiUxcollqS2WoW2Xhsgl/EfmSZUjvJ0schlT1ahHLpqdeh42dM/O80fR8mxxTbPWDsNw+2PX6Tbd2ihW8aktEV5knbHccxGWlT0Xkae+41Pp1BU7S1Byu5lh+HX7LfLcy/NY3U7WYloNYuQyl1Wc41ZHYnHQ6+3y7JOv22h5VsIiSLTP6le5LVO+4PI1ywmj7AccRZ+Sk3xDt3K28sGczyO4GojLTD7rbsYGrwFxgU8HcXlTzucRXI3ziMv5/v53owL8iJOICwC8G4gLAHQBcQGALiAuANAFxAUAuoC4AEAXEBcA6EJbXNTLDbMfjCiXGwLA1WmJixeXG4bk+Cs45XJDALg6DXHRLzf0drD2+auMAOBCNMRFu9xwvodj3xVkAHBVmuJSXhEUrt4oxQVlAYCU5rIoW/LcxdUEq9KgLACQ0hCXyuWGUxq5VC43BIBL0zyKFpcbpmmD+ftVu9wQAC4NX6IDgC4gLgDQBcQFALqAuABAFxAXAOjCP+aF+2C3sbpdAAAAAElFTkSuQmCC" alt="" />

  我在函数里面有嵌套了一个函数,当我向外层函数传递一变量的之后,并赋值给 a ,我们发现 a 变成了一个函数对象,而我再次为这个函数对象传参的时候,又获得了内部函数的返回值。我们知道,按照作用域的原则来说,我们在全局作用域是不能访问局部作用域的。但是,这里通过讨巧的方法访问到了内部函数。。

  下面我们继续看一个例子:

def wai_hanshu():
a = []
def nei_hanshu(canshu):
a.append(canshu)
return a return nei_hanshu a = wai_hanshu()
print a(123)
print a(321)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARgAAAAvCAIAAAC35EJ6AAAB+UlEQVR4nO3cy3HCMBhF4b8sNRSVAR1olyqyRftUwcYdpAlnEZDfL+aKkaPzrRJAssnMGYNtxdpX3L19hmbx6ei/4kvz6qQ9vHub2ZkC9lDrJ7iLf9Nbeue2SrP43k26mbu3i9m1nL9y9Bezq7nvZ/XF7SH+B21IQKUICRAgJECAkAABQgIECAkQICRAYBBS9GZmZm7lYuuGJri/ObhSg5oMQwqvFzTUhEBIqMhGSNH3jizpaJOON89D2OQIREioy3JIj0hSIE34eD4bvZm/tdGnz4BNcIOUCAl1WT8iRd/lsfTz7AOEhLrsD6nTBNc7HRH9zKkFQkJdDoc0rGjphYSEuhwLKfqlU+OjVxIS6nIgpCa43pmHMDjZMC6MkFCXzbN26cxd7/d0zbZ7bPQJkJBQF+5sAAS41w4QICRAgJAAAUICBAgJECAkQICQAAFCAgTUF2Tz4VIvCpZpqXk+3HyEEmVaar5qOmo683TraScICeXJtNR8xXjUbTJz7xZZQsI5ZFpqvs9j1O6ttC0hoUyZlppvmh81mZmQcA6ZlprvMxw1mZmQcBqZlprv1I2am5mQcBrypeabRc2MGs3MdyScjnypea+TJeNR6zPzP1xxAto7G+a/QGlwZwMKxr12gAAhAQKEBAgQEiBASIAAIQEChAQIEBIg8Au5I5F96BtFQQAAAABJRU5ErkJggg==" alt="" />

  可以看出函数位于外部函数中的列表 a 竟然改变了。要知道为什么,就要先知道什么是python的命名空间,而命名空间就是作用域表现的原因,这里我简要说明一下。

  引入命名空间的主要原因还是为了避免变量冲突,因为python中的模块众多,模块中又有函数,类等,它们都要使用到变量。但如果每次都要注意不和其他变量名冲突,那就太麻烦了,开发人员应该专注于自己的问题,而不是考虑别人写的程序中用到了什么变量,所以python引入了命名空间。命名空间分为模块层,模块内又分为全局作用域和局部作用域,用一个图来表示的话:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAnkAAAJgCAIAAAB5suKlAAAgAElEQVR4nO2dsW7jxsJG95nkxsDdIJvm+gH0DH8bICYWBgQYwV0EfgBVqfIAqRQ3TuFbLAK48S30En4BFa4M8C8oURxyyBlKw08znHOqXevT6DNHnOOhZOtT6WK32zkzgvDb21sMNeisqUFnTQ06a2rQWVMj5s6fBI8RJMxcasJ01oTprAnTWROmszOMa+lsQGdNmM6aMJ01YTo7w7iWzgZ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1dDYI1Xm1Wl16PQSYir/++iv+c1AZprMzjGvpbEBnTZjOmjCdNWE6O8O4ls4GdNaE6awJ01kTprMzjGvpbEBnTZjOmjCdNWE6O8O4ls4GdNaE6awJ01kTprMzjGvpbEBnTZjOmjCdNWE6O8O4ls4GdNaE6awJ01kTprMzjGvpbEBnTZjOmjCdNWE6O8O4ls4GdNaE6awJ01kTprMzjGvpbEBnTZjOmjCdNWE6O8N8pt6E0FkDnTXQWQOdNYg7s6+lswGdNWE6a8J01oTp7AzjWjob0FkTprMmTGdNmM7OMK6lswGdNWE6a8J01oTp7AzjWjob0FkTprMmTGdNmM7OMK6lswGdNWE6a8J01oTp7AzjWjob0FkTprMmTGdNmM7OMK6lswGdNWE6a8J01oTp7AzjWjob0FkTprMmTGdNmM7OMK6lswGdNWE6a8J01oTp7AzjWjob0FkTprMmTGdNmM7OMK6lswGdNWE6a8J01oTp7AzjWjob0FkTprMmTGdNmM7OMK6lswGdNWE6a8J01oTp7AzjWjob0FkTprMmTGdNmM7OMJ+pNyF01kBnDXTWQGcN4s7sa+lsQGdNmM6aMJ01YTo7w7iWzgZ01oTprAnTWROmszOMa+lsQGdNmM6aMJ01YTo7w7iWzgZ01oTprAnTWROmszOMa+lsQGdNmM6aMJ01YTo7w7iWzgZ01oTprAnTWROmszOMa+lsQGdNmM6aMJ01YTo7w7iWzgZ01oTprAnTWROmszOMa+lsQGdNmM6aMJ01YTo7w7iWzgZ01oTprAnTWROmszOMa+lsQGdNmM6aMJ01YTo7w7iWzgZ01oTprAnTWROmszOMa+lsQGdNmM6aMJ01YTo7w7iWzgZ01oTprAnTWROmszP86c3FbrdzZgThUdD55PAo6HxyeBR0Pjk8CjqfHB5Fnp3/H43FG/bh57aPAAAAAElFTkSuQmCC" alt="" />

  模块之间命名空间不同,而里面还有全局作用域和局部作用域,局部作用域之前还能嵌套,这样就能保证变量名不冲突了。这里顺便补充一下,可以通过 __name__ 属性获取命名空间的名字:

aaarticlea/png;base64,iVBORw0KGgoAA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8HEpLxDWCQkIzvFISE4FHABTEKuOCuB1yQRwEXZGbBBUIBFwgFXJTfAA7KLwAH5Q+Agy+C+cS+kyeASAAAAABJRU5ErkJggg==" alt="" />

  主文件的命名空间是叫做 '__main__',而模块的命名空间就是模块名。

  作用域的诞生,是因为当python在寻找一个变量的时候,首先会在当前的命名空间中寻找,如果当前命名空间中没有,就到上一级的命名空间中找,以此类推,如果最后都没找到,则触发变量没找到的异常。

  我们之前一直说:全局作用域无法访问局部作用域,而局部作用域能够访问全局作用域就这这个原因。而当我在局部作用域创建了一个和外面同名的变量时,python在找这个变量的时候首先会在当前作用域中找,找到了,就不继续往上一级找了。

  在早期的python版本时,局部作用域是不能访问其他的局部作用域的,只能访问全局的,而现在的版本都是依次向上一级找,这里就提一下。

  也就是因为这个特性,我们可以在内部函数中访问外部函数中的变量,这也就是所谓的闭包了。

  注意:这里要做好对象之间的区分,例如:

def wai_hanshu():
a = []
def nei_hanshu(canshu):
a.append(canshu)
return a return nei_hanshu a = wai_hanshu() # 我创建了一个对象
b = wai_hanshu() # 我又创建了一个对象
print a
print b
print a(123)
print b(321)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWEAAABnCAIAAABes2QpAAAK7ElEQVR4nO2dPXasPBKG2dXHEmYHk5GZZdjMAobsZhORdmpyHxbh4CMi9RYMzQTopySVqqEbu0Hf+5x7fNptUfqtVyUButm8gjr/U/f6l/6rl9J+ltmlZT7rq+s/ef01t5eyZS+hv276MLfla15/eaVpS78AkRLaL3+uhFxbvWbZW5a9ZU6RSGvzaShfa3unvWT5B/krW8IlO2MwzJ2tjncVm5e2o753cn9Xv9KfXiHlMntFCsoTteO2D9MXK/vdtUPr3l7y+qPMXjO/kdlW3TSQYn8KO3RND7pfklpkfmIO5TaLrfJTTtyWr9q72NJ81flrxlap/Yw0inaD/iPnRlg7z339x7h0X38IIhWU0LP8UyXkIO6tfPurzi+t+hlL47Oud77q/LV0ykHqrotaGztevWzuzEjlrnLz6j9etHy35W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EAjAAAS0AgAgAQ0AgAgAY0AAEj8HxyZi7ZlWt36AAAAAElFTkSuQmCC" alt="" />

  在这里,我们虽然都是操作 wai_hanshu 中的变量,但是 a 和 b 完全是两个对象,它们所在的内存空间也是不同的,所以里面的数据也是独立的。要注意不要搞混。


装饰器

  其实装饰器就是在闭包的基础上多进行了几步,看代码:

def zsq(func):  # 装饰函数
def nei():
print '我在传入的函数执行之前做一些操作'
func() # 执行函数
print '我在目标函数执行后再做一些事情'
return nei def login(): # 被装饰函数
print '我进行了登录功能' login = zsq(login) # 我将被装饰的函数传入装饰函数中,并覆盖了原函数的入口 login() # 此时执行的就是被装饰后的函数了

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAV4AAABECAIAAABGc8oEAAAGS0lEQVR4nO2cwZHcRgxFGZYjUhhSBr45FN0dhS9OYLOgD1ZtsYCPD5BDrof0e4ctThON/k02PqndUS8fHx8fHx/rl/LXt+X7svz49vNrh635+e37svxYfvvz718Nb6cQ/p+klTnh1+pdlj9+39MtsPwX1gAA7w7WAAACrAEABFgDAAiwBgAQYA0AIMAaAEBw0BqWZVmW5d8DH9bm8cGfA81HyfFLwV49rdrh2cNJqpbP9uG47XD+4vjLOFkY8P7stoawIPyifN0aDpyaLEq/oKvFvVdt60St2mG5vmgNeb4yoW802eCOHH9rCAfrZk142ng/YmjMHUPLrgqfLHqjx7TvYngNzcHe4baDrkV5yys8jDnlssBXcqY1VDGTgF3BJkPVUlVRqIpQHvJjjs96/HSKet9dP17YgTxBoRQ8T4Ud3Jp91mDWdF43smZCKhOQU8kkVcLcS67aKkMVkI8rVXsrP4uXHbfjyqlJSR5pDTlVmFc4XtMtwBpuzVVvDcYmVls8soSG1iAPJkqCpKr7xBqMfsNkapMCri7UZPRQ8xMZ1c/P+OqGwvtzmjXkNSHjfRI/nKwfuf7kYm0bZYycV3aQVmc7u3ZqlTWYmKUjdJcCvCR55SezhjfnnD9emvLI6ylE+hiZvD2VtW3Hkjqr5EGkFG8EVy3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eaJl4VUUjY8hks2gGtLWrZUeaoCzqPLpW9ipOZcEjLbgalVczTHuaQn9RzmIhVWJS31yCs5nCzclPM3gPMrOGSo1rTM4xtN+5pWsBSZg2VRDVvaqU2Oq58nYm6EuSwyAJ7E5RvAVTHVkqo6elMwfSe+U2V+0Rqq9kkpnmgNvuDNdPy9kDHwGK7dAK76KFtMxzyErO12Kc/XfVWN7UTkWO2pSp70i9NpfSrrn7gM3JpLNoBb64LZtuxajsO01dmQuRJc6fQTkR/N1HZZQ6vwXEx+qR9reCrnbwD3+XF9uTxWW95V/jBWHtTobCVlPeZslae6eqb7sWqcXJ8cb7Llg7kYuBf89yoAEGANACDAGgBAgDUAgABrAAAB1gAAAqwBAARYAwAIsAYAEGANACD4B7ek2DFDm+K8AAAAAElFTkSuQmCC" alt="" />

  在看这段代码的时候,要知道几件事:

  1.函数的参数传递的其实是引用,而不是值。

  2.函数名也是一个变量,所以可以重新赋值。

  3.赋值操作的时候,先执行等号右边的。

  只有明白了上面这些事之后,再结合一下代码,应该就能明白什么是装饰器了。所谓装饰器就是在闭包的基础上传递了一个函数,然后覆盖原来函数的执行入口,以后调用这个函数的时候,就可以额外实现一些功能了。装饰器的存在主要是为了不修改原函数的代码,也不修改其他调用这个函数的代码,就能实现功能的拓展。

  而python觉得让你每次都进行重命名操作实在太不方便,于是就给出了一个便利的写法:

def zsq(func):
def nei():
print '我在传入的函数执行之前做一些操作'
func() # 执行函数
print '我在目标函数执行后再做一些事情'
return nei @zsq # 自动将其下面的函数作为参数传到装饰函数中去
def login():
print '我进行了登录功能' login()

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOoAAABHCAIAAACGdEwpAAAGKElEQVR4nO1awZHkRgxTWBfRhrGXwf0chd/7dxT7cQZOQn64PJZJAERLGkldRTy2eig2CZLonqmZXdaj+P5Yfvv1J3389fH71+Ecx/Bi+P2xADIPYHgu/vr14/PjopKuzAWwvC3y98fyuSw/b6wt4Ovjc1l+Lj/++PesPY5hYxT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dva/eZoANe00Rf660ntIRopcV8evA46QMpbt++gB+LWkn6zbSc6InyFUmFNOE9LSyiwJbv0+B+eAjGrA/2tg49RUaWVMBhHhyEP7x0NfPGXeh5NCZGy7cxMVq+jYnR8m1MjJZvY2K0fBsTo+XbmBgD//Mg3I6SMH77cL7xXatfGfTTIUqMoSacmYcOH2nmKdXlL8V387kA1i8Iurm6F47y2NQVb/7/OmvSBNzljFBzNqk6uQ7KN9cbAhaHifxqM1TjLbAkYpaXS2U1Zyk4NKBFhBraaJLx3XytwMUQwlBWJGgzHWP4TAzLl/kMPd1GLg93mERYsOOUg7NHWk/7Cg8Oei04m8hihRFylyAZ6OyTuRL4w4BGcIbrMlQOwtwWoldIINsZQ+jg8DFLc/LC0iAljbC9DCWMYr4PxKHbtyzV2cjUPPpyq7lgYXlZQKeQcq6lviEHqKES4byxyM55C6Eg7edgTL5DsoMWFoeJLGeH4xE+kHMeG4y2ozRWo1hn2TmaC7VAhkx2kA/spFnsXSjkK3Sw8i6HCKzvMI42CvuaugxJZmc4eNNSluas2d8TIQYh2gIdHgVKi1UVfMRLtkts1MIVe52zwSIflC+zO3I5Ub5alKIcPQvo8xxgUWYZOVUdlG9OAfVXttufDVNMWQjMVT5i9KCmT0d5ljJ/5yTci+LDw1qJKfsHy1DLzLDsaYjMCDOeuhD4UpQ2JN+S4bkQ8SH/+eQLzxzTx5ERrlKCLH7IlZMKniWlzEc8ZXFY98T2fYpx+pP9RbS88MlcjIfSajQctHwbE6Pl25gYLd/GxGj5NiZGy7cxMVq+jYnR8m1MjJZvY2K0fBsTo+XbmBgt38bE+BsQyxO31yF9xAAAAABJRU5ErkJggg==" alt="" />  

  这些小便利也叫做python的语法糖,你可能在很多地方见过这个说法。

带参数的装饰器:

def zsq(a):
print '我是装饰器的参数', a
def nei(func):
print '我在传入的函数执行之前做一些操作'
func() # 执行函数
print '我在目标函数执行后再做一些事情'
return nei @zsq('')
def login():
print '我进行了登录功能'

aaarticlea/png;base64,iVBORw0KGgoA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SDjwxeLBzqk1Aswy998ep7rEm1d2dfnmqu7IkD0m1dTApph+WL/sZWOK8KGcypua01UKAR7nlhNVMVNHr5mHX7mhqEKjcsacvDrkrWFt4SHAt43mJtl3ZIZ8lqQYGdwXA9Bk/cs8X5RVjQ1T5SRV2FFYjxSQ+yuFMqCjp7m0zrxyaVKSJwwfpjKd5vMFeJbH9kTDq7YzsDKm2bdX+wg91bxVws5ChiU6tCqpQdrBkGCdVeaOdYZUUjbAI6w70ZSDyJ4qT+UXeXZZaSZGas4VKLMtLK1ao2lnB+nYR1iLVFg5iNQjz2RzsQALTDiRKemzLpiQoSohmcd3mv4zFYwUmYNlDTd7hkvrtKvXBzEfhDktMgDgKVpXVXWBhhjzthplBnoPMmM7NldlvulEVX+n8h90Iu8vZjn+s5AxAI8wvq3IjtC5QG86UZ5CWsmwcvplVhX/cCFyruGhSp60p8cZ2mLW3zE1gGUm7s7OkS/k+NAzdfU301ZHQ+ZKcKXTL0S+NUubcqKhwmcx+aV+nAj+Bit3Z7LzVTZ3qvG0blLlD3PlSY3OoaSsxxyt8lRnzwxfK/7O+cnxJltu9MUA9OGqAoD94EQAsB+cCAD2gxMBwH5wIgDYD04EAPvBiQBgPzgRAOwHJwKA/eBEALAfnAgA9oMTAcB+cCIA2A9OBAD7wYkAYD//AO6cZJwOOdXlAAAAAElFTkSuQmCC" alt="" />

  相当于: login = zsq(123)(login) ,所以在这里没有调用就执行了。

装饰器的嵌套:

  这里就不完整写个例子了:

@deco1(deco_arg)
@deco2
def func():
pass

  相当于: func = deco1(deco_arg)(deco2(func))

  也就是从上到下的嵌套了。


  关于闭包和装饰器就先讲到这里,以后有需要再补充。