Python装饰器:加倍输出

2024-03-28 14:37:32 发布

您现在位置:Python中文网/ 问答频道 /正文

在Windows XP(sp3)机器上使用Python 3.4.4时,以下代码(出于教育目的使用基本修饰符)显示加倍的输出,我不知道为什么:

def decorated_by(func):
    func.__doc__ += '\nDecorated by decorated_by!!!'
    return func

@decorated_by
def add(x, y):
    '''Return the sum of x and y.'''
    return x + y

add = decorated_by(add)
print (help(add))

输出

C:\>python test30.py
Return the sum of x and y.
Decorated by decorated_by!!!
Decorated by decorated_by!!!

代码正在命令行上的文件中运行

谢谢


Tags: andofthe代码addbyreturnwindows