Discuss / Python / 答案

答案

Topic source

popwbob

#1 Created at ... [Delete] [Delete and Lock User]
def log(arg):
    def wrapper(fn):
        def run():
            if not callable(arg): print(arg)
            print('begin call')
            fn()
            print('end call')
        return run
    return  wrapper(arg) if callable(arg) else (lambda fn : wrapper(fn))

@log
def now():
    print('now 2015')

@log('execute')
def pas():
    print('pass 2014')

now()
print("="*20)
pas()

  • 1

Reply