Python into the pit road--decorator (grammar sugar)--close

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.