Discuss / Python / 请求。。。

请求。。。

Topic source

lina19820525

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

def metric(fn):

    def wrapper(*args, **kw):

        t0 = time.time()

        te = fn(*args, **kw)

        print('%s executed in %s ms' % (fn.__name__, time.time() - t0))

        return te

    return wrapper

lina19820525

#2 Created at ... [Delete] [Delete and Lock User]
def log(text):    def decorator(func):        def wrapper(*args, **kw):            print('begin call')            re = func(*args, **kw)            print('end call')            return re        return wrapper    return decorator@log('execute')def f():    print('producing')f()

  • 1

Reply