1
#!/usr/bin/env python3 # _*_ coding:utf-8 _*_ login_status=0 def login(arg): def wrapper(fun1): def inner(k1): global login_status if login_status==0: username = input('username: ') password = input('password: ') if arg=='web': if username=='a' and password=='a': login_status=1 else: print("login error") return 0 elif arg=='weixin': if username=='b' and password=='b': login_status=1 else: print('login error') return 0 elif login_status==1: pass print('in decorater...') fun1(k1) return inner return wrapper @login('web') def index(url): print('in index/%s'%url) @login('weixin') def pay(url): print('in pay/%s'%url) while True: choice=input('select 123: ') choice_dict={'1':index,'2':pay} choice_dict.get(choice)('abc')