The last time we said, the incoming function with parameters, this time we want to say that the adorner with parameters, then how the adorner is good.
1u_n="Keven"2Passwd="abc123"3 4 defAuth (auth_type):5 defOuter_wrapper (func):6 defWrapper (*args,**Kwargs):7 Print(*args,**Kwargs)8Username=input ("pls input your username:"). Strip ()9Passwrod=input ("pls input your password:"). Strip ()Ten ifauth_type=="Local": One ifusername== U_n andpasswrod==passwd: A Print("\033[5;40m user has pass authentication \033[0m")#add color to font, install x -res=func () - Print("After authentication")#W to verify that the function results can be returned after the function has been executed. the returnRes - Else: - Print("Invalid Passwrod or username") - elifAuth_type = ="LDAP": + Print("It's so complicated, the teacher doesn't show it, I don't understand .") - Pass + A returnWrapper#do remember must not have parentheses, with pycharm automatic completion will always have parentheses, pits. at returnOuter_wrapper - - - defindex (): - Print("welcome to the index") - in@auth (auth_type="Local") #装饰器带参数 - defHome (): to Print("welcome to the home") + -@auth (auth_type="LDAP") #装饰器带参数 the defBBS (): * Print("welcome to the BBS") $ Panax Notoginseng - index () the Home () +BBS ()
Python into the pit road--decorator (grammar sugar)--close