python 装饰器demo
作者:互联网
普通装饰器
from functools import wraps
def cover(func):
@wraps(func)
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return result
return wrapper
类内部装饰器,可调用类内部函数
from functools import wraps
class T(object):
def __init__(self):
pass
def cover(func):
"""读取最新的数据到内存,写数据到硬盘"""
@wraps(func)
def wrapper(self, *args, **kwargs):
do_something()
result = func(self, *args, **kwargs)
do_else()
return result
return wrapper
@cover
def get_schema(self, arg1, arg2):
work...
标签:wraps,python,demo,self,wrapper,result,func,装饰,def 来源: https://www.cnblogs.com/jade-north/p/15175725.html