标签:html time() app int index 等于 **kwargs class http
#闭包,嵌套函数,内部函数调用外部函数的变量 # def outer(): # a = 1 # def inner(): # print(a) # return inner # # inn = outer() # inn() # # from urllib.request import urlopen # # def get_url(): # url = ‘http://www.xiaohua100.cn/index.html‘ # def get(): # geting = urlopen(url).read() # print(geting) # return get # # wget = get_url() # wget()
# 装饰器的雏形 # def wrapper(f): # def inner(): # f() # print(1) # return inner # # def func(): # print(2) # # f = wrapper(func) # f() # 装饰器形成的过程 : 有返回值的 有一个参数*args 万能参数**kwargs # 装饰器的作用 # 原则 :开放封闭原则 # 语法糖 :@ # 装饰器的固定模式 # import time # # # def wraper(f): # 装饰器函数,f是被装饰的函数 # def inner(*args, **kwargs): # start = time.time() # f(*args, **kwargs) # end = time.time() # c = end - start # print(c) # return inner # # # @wraper # 语法糖,装饰器函数名,等于 sleeps = wraper(sleeps) # def sleeps(a, b): # 被装饰的函数,带2个参数 # time.sleep(2) # print("睡眠2秒", a, b) # # # @wraper # 语法糖,装饰器函数名,等于 sleeps = wraper(sleeps) # def sleeps1(a): # 被装饰的函数,带1个参数 # time.sleep(2) # print("睡眠2秒", a) # # sleeps(1, b =2) # sleeps1(1)
标签:html time() app int index 等于 **kwargs class http
原文地址:https://www.cnblogs.com/hhsh/p/9534979.html