zoukankan      html  css  js  c++  java
  • day14 装饰器模拟验证附加功能

     1 user_list=[
     2     {'name':'alex','passwd':'123'},
     3     {'name':'linhaifeng','passwd':'123'},
     4     {'name':'wupeiqi','passwd':'123'},
     5     {'name':'yuanhao','passwd':'123'},
     6 ]
     7 current_dic={'username':None,'login':False}
     8 
     9 
    10 def auth_func(func):
    11     def wrapper(*args,**kwargs):
    12         if current_dic['username'] and current_dic['login']:
    13             res = func(*args, **kwargs)
    14             return res
    15         username=input('用户名:').strip()
    16         passwd=input('密码:').strip()
    17         for user_dic in user_list:
    18             if username == user_dic['name'] and passwd == user_dic['passwd']:
    19                 current_dic['username']=username
    20                 current_dic['login']=True
    21                 res = func(*args, **kwargs)
    22                 return res
    23         else:
    24             print('用户名或者密码错误')
    25 
    26     return wrapper
    27 
    28 @auth_func
    29 def index():
    30     print('欢迎来到京东主页')
    31 
    32 @auth_func
    33 def home(name):
    34     print('欢迎回家%s' %name)
    35 
    36 @auth_func
    37 def shopping_car(name):
    38     print('%s的购物车里有[%s,%s,%s]' %(name,'奶茶','妹妹','娃娃'))
    39 
    40 print('before-->',current_dic)
    41 index()
    42 print('after--->',current_dic)
    43 shopping_car(current_dic["username"])
    44 home('产品经理')
    45 # shopping_car('产品经理')
    1 before--> {'username': None, 'login': False}
    2 用户名:alex
    3 密码:123
    4 欢迎来到京东主页
    5 after---> {'username': 'alex', 'login': True}
    6 欢迎回家产品经理
    7 alex的购物车里有[奶茶,妹妹,娃娃]
  • 相关阅读:
    flex 图表使用百分比示例
    flex 图标设置百分比或者其它符号
    大学生求职(打油诗一首)
    flex 图表categoryField设置 labelFunction使用
    如何配置EclipseMe
    google chart图表使用
    Codeforces #Round 632 div2 A~C
    牛客的两道dfs
    约数
    Atcoder ABC162 D RGB Triplets
  • 原文地址:https://www.cnblogs.com/shijieli/p/9705955.html
Copyright © 2011-2022 走看看