带参数的函数增加装饰器


带参数的函数增加装饰器:

# !/usr/bin/env python
# -*- coding: utf-8 -*-
import time
def tips(func):
    def nei(a,b):
        print 'start'
        func(a,b)
        print 'stop'
    return nei
@tips
def add(a,b):
    print  a+b
print add(11,22)


C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled2/socket/fun6.py
start
33
stop
None

Process finished with exit code 0
原文地址:https://www.cnblogs.com/hzcya1995/p/13348285.html