装饰器

#!/usr/bin/env python
# -*- coding:utf-8 -*-

def auth(func):
    def wrapper():
        user = raw_input('input name: ').strip()
        if user == 'alex':
            print '--------welcome login--------'
            func()
        else:
            print '-------wrong passwd,access denied!-------'
    return wrapper
@auth
def task1():
    print 'do something......1'

def task2():
    print 'do something---------2'

def task3():
    print 'do something---------3'


task1()

 

posted @ 2016-03-04 17:45  fengjian1585  阅读(115)  评论(0编辑  收藏  举报