python 函数后阶


#最完整的装饰器
# import time
# flag = True
# def timmer_out(f):
# def timer(func):
# def inner(*args,**kwargs):
# if f:
# start_time = time.time()
# time.sleep(1)
# ret = func(*args,**kwargs)
# old_time = time.time()
# print("时间%s"%(old_time - start_time))
# return ret
# else:
# ret2 = func(*args,**kwargs)
# return ret2
# return inner
# return timer
# @timmer_out(flag) # 执行两步
# def func():
# print("已执行")
# func()


#一个函数装饰多个装饰器

# def wrapper(func):
# def inner():
# print("wrapper1,before func")
# func()
# print("wrapperl,after func")
# return inner
# def wrapper2(func):
# def inner():
# print("wrapperl,befor func")
# func()
# print("wrapper2,after func")
# return inner
#
# @wrapper2
# @wrapper
# def f():
# print("in f")
# f()

# 获取函数的注释 和 函数名字
# def f():
# """
# 此函数只是实验用
#
# :return:
# """
# f()
# print(f.__doc__)
# print(f.__name__)




# from functools import wraps
# def wrapper(func):
# @wraps(func)
# def inner(*args,**kwargs):
# '''执行函数前进行的操作'''
# ret = func(*args,**kwargs)
# '''执行函数后进行的操作'''
# return ret
# return inner
#
# @wrapper
# def f1():
# '''
# 本函数的功能:绘图功能,实时接收数据并绘图.
# :return: 绘图需要的数据,返回给前端某标签
# '''
# print(f1.__doc__)
# print(f1.__name__)
# f1()


# 装饰器里 * 打散 也可以
# def wrapper(f):
# def inner(*args,**kwargs):
# """执行前的函数"""
# ret = f(*args,**kwargs)
# """执行后的参数"""
# return ret
# return inner
# @wrapper
# def func(*args,**kwargs):
# print(args[0:2])
# func(*[1,2,3,4,5,5,66,77,2])

相关内容推荐