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

python 装饰器

时间:2019-10-23 00:18:42      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:python   xxxx   xxx   tor   col   time()   import   name   ora   

 

import time 

def decorator(func):
    def wrapper():
        print time.time()
        func()
    return wrapper

def f1():
    print(xxxxxx)

f= decorator(f1)
f()

 

import time 

def decorator(func):
    def wrapper():
        print time.time()
        func()
    return wrapper

@decorator
def f1():
    print(xxxxxx)

f1()

 


 

 

import time 

def decorator(func):
    def wrapper(name):
        print time.time()
        func(name)
    return wrapper

@decorator
def f1(name):
    print(xxxxxx+name)

f1(eeeee)

import time 

def decorator(func):
    def wrapper(*args):
        print time.time()
        func(*args)
    return wrapper

@decorator
def f2(n,m):
    print(xxxxxx+n+m)

f2(1,3)

 

python 装饰器

标签:python   xxxx   xxx   tor   col   time()   import   name   ora   

原文地址:https://www.cnblogs.com/angdh/p/11723308.html

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