装饰器
#!/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()