参数化装饰器(Python)

问题描述 投票:0回答:0
def outer_function(function):

    def wrapper(arg1, arg2):
        print("My arguments are: {0}, {1}".format(arg1,arg2))
        function(arg1, arg2)
    return wrapper

@outer_functiondef cities(city_one, city_two):

    print("Cities I love are {0} and {1}".format(city_one, city_two))

cities("Nairobi", "Accra")

大家好。在下面的程序中,我不知道包装器类是如何识别arg1 和arg2 的。请带我离开这个问题。

python-decorators
© www.soinside.com 2019 - 2024. All rights reserved.