python装饰器
来源:互联网 发布:php oa 工作流引擎 编辑:程序博客网 时间:2024/06/11 17:51
# -*-coding : utf-8 -*-def log(func): def wrapper(*args, **kw): print('call %s():' % func.__name__) return func(*args, **kw) return wrapper'''foo(): print('1111')f=foof()>>>1111'''@logdef now(): print('2015-3-25')#now = log(now) #这里log(now)的返回值就是wrapper,now变量被赋值一个函数名,可以用@log代替此句now()#执行的是上一句的wrapper函数,在这个函数中,先执行print(),再执行func(),func()就是本身的now(),#如果不执行now = log(now),函数now()直接就是now()函数。#有些依赖函数签名的代码执行就会出错,需要@functools.wraps(func),将wrapper这个函数里面wrapper.__name__ = func.__name__。#只需记住在定义wrapper()的前面加上@functools.wraps(func)即可。print(now.__name__)
0 0
- python装饰器装饰类
- [python]python装饰器
- Python装饰器学习
- Python装饰器
- python 装饰器
- Python装饰器
- python 装饰器 应用
- python 装饰器2
- Python装饰器学习
- python装饰器
- python装饰器
- python 装饰器入门
- python装饰器
- python装饰器
- python 装饰器'@'
- python装饰器
- Python装饰器详解
- python 装饰器
- 初学Hibernate,从建立项目,配置文件到实现对单表的增删改查
- XMU 1606 nc与滴水问题 【模拟】
- hiho Coder hiho字符串
- 翻转二叉树
- 练习
- python装饰器
- 漫谈千亿级数据优化实践:数据倾斜(纯干货)
- python Image库
- CAS实现单点登入(二):自定义的用户验证登入
- 数码管
- 子树
- [2017.4.20]IMWEB前端小白训练营日记(六)
- android 仿 淘宝淘口令
- win7+ubuntu虚拟机+hadoop2.6.0+eclipse(实体机)环境配置