码迷,mamicode.com
首页 > 编程语言 > 详细

python 装饰器

时间:2016-03-20 00:30:51      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

from _ctypes_test import func



def deco1(arg):
    def mid_deco1(function):
        def new_func():
            print ("deco1 > new_function : arg=%s" %(arg))
            return function()
        return new_func
    return mid_deco1

@deco1("abc")
def function1():
    print "function1"


def deco2(arg):
    def mid_deco2(function):
        def new_func(a):
            print ("deco2 > new_function : arg=%s" %(arg))
            return function(a)
        return new_func
    return mid_deco2

    
@deco1("abc")
def function2(a):
    print "function2"
    
    
if "__name__" == "__main__":
    function1()
    function2()

 

python 装饰器

标签:

原文地址:http://www.cnblogs.com/lifeinsmile/p/5245750.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!