Discuss / Python / 也不知道对不对。。

也不知道对不对。。

Topic source

虚空螺旋

#1 Created at ... [Delete] [Delete and Lock User]
在此插入代码import functools
def log(text = None):
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*argc, **kw):
            print ('call begin')
            if text == None:
                print ('%s' % func.__name__)
            else:
                print ('%s %s' %(text, func.__name__))
            ret = func(*argc, **kw)
            print ('call end')
            return ret
        return wrapper
    return decorator    

@log('lalla')
def f():
    pass
print (f())

@log()
def f():
    pass
print (f())

东东男装

#2 Created at ... [Delete] [Delete and Lock User]

测试OK


  • 1

Reply