アクセサリーの使用

905 ワード

def debug(func):
    def wrapper(*args, **kwargs):  #     
        print("[DEBUG]: enter {}()".format(func.__name__))
        print('Prepare and say...')
        return func(*args, **kwargs)
    return wrapper  #   
@debug
def say(something):
    print("hello {}!".format(something))
print(say('python'))

戻る
[DEBUG]: enter say()
Prepare and say...
hello python!
None

テスト:
def debug(func):
    def wrapper(*args, **kwargs):  #     
        print("[DEBUG]: enter {}()".format(func.__name__))
        print('Prepare and say...')
        # return func(*args, **kwargs)
    return wrapper  #   
@debug
def say(something):
    print("hello {}!".format(something))
print(say('python'))

戻る
[DEBUG]: enter say()
Prepare and say...
None