2 Star 3 Fork 3

celaraze / learning-python

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
16.装饰器.py 438 Bytes
Copy Edit Raw Blame History
# 函数对象有一个_name_属性,可以拿到函数名字
def now():
print('2019年12月30日')
f = now
f()
print(now.__name__)
# 代码运行期间动态增加功能的方式叫做修饰器decorator
def log(f):
def wrapper(*args, **kw):
print('call %s():' % f.__name__)
return f(*args, **kw)
return wrapper
# @log相当于 now = log(now)
@log
def nowTwo():
print('2019年12月30日')
nowTwo()
Python
1
https://gitee.com/celaraze/learning-python.git
git@gitee.com:celaraze/learning-python.git
celaraze
learning-python
learning-python
master

Search