摘要: from functools import wraps def wrap1(f): @wraps(f) def inner1(): print('inner1() before') f() print('inner1() after') return inner1 def wrap2(f): @wr 阅读全文
posted @ 2018-08-25 23:17 该搬砖啦 阅读(93) 评论(0) 推荐(0) 编辑
摘要: #闭包,嵌套函数,内部函数调用外部函数的变量 # def outer(): # a = 1 # def inner(): # print(a) # return inner # # inn = outer() # inn() # # from urllib.request import urlope 阅读全文
posted @ 2018-08-25 18:39 该搬砖啦 阅读(114) 评论(0) 推荐(0) 编辑
摘要: # a = 1 # def outer(): # a = 2 # def inner(): # a = 3 # # def inner2(): # nonlocal a #nonlocal只能用于局部变量,找最近一层的局部变量 # a += 1 # inner2() # print('inner() 阅读全文
posted @ 2018-08-25 18:36 该搬砖啦 阅读(125) 评论(0) 推荐(0) 编辑