Python装飾器伝参(外部伝参)

1127 ワード

def get_temp(temp_out):  # temp_out    ===>"  "

    def get_test(test):
        def get_current_test(temp_in):  # temp_in===>"    "
            data = test()  #   test()  ===>print("test")

            return data

        return get_current_test

    print(temp_out)  # temp_out    ===>"  "
    return get_test


"""
    @get_temp("  ")     1.get_temp("  ")
    1.get_temp("  ")====>  get_temp()      get_current_test  
    2.@        get_current_test  ===>@get_current_test===>test=get_current_test(test) 
"""


@get_temp("  ")  # "  "===>   get_temp(temp_out)
def test():
    print("test")

    return "     --123"


result = test("    ")

print(result)  # ====>test()    "     --123"

----------------------------------------------------------------------------------------
/Users/YZH/Desktop/python_18/venv/bin/python/Users/YZH/Desktop/python_18/yzh_アクセサリー/python_装饰器传参py李想test関数戻り値--123
Process finished with exit code 0