使decorators具有before和after函数
Easy_Decorator的Python项目详细描述
只需使用before和after函数制作装饰器。
包含的文件
- easydecorator/easydecorator.py版本 -使用before和after函数制作装饰器
安装
必须安装python才能导入菜单。在https://www.python.org/download/安装python。在终端中键入“cd path/to/this/directory”,然后键入“python setup.py install”。这将把菜单模块添加到站点包中。
如何使用
导入EastDecorator:
from easyDecorator import easyDecorator as dec
或:
import easyDecorator.easyDecorator as dec
使用before/after函数制作装饰器:
newDecorator = dec.decorator(before=beforeFunction,after=afterFunction) @newDecorator def someFunc(): pass
修饰不接受参数的函数,以便它可以:
@dec.giveArgs def funcWithoutArgs(): pass