Python--------------Decorator Exercises

Source: Internet
Author: User

 fromFunctoolsImportWraps#1. Write adorners to add authentication functions to multiple functions (the user's account password originates from the file)#Once the login is successful, subsequent functions do not need to enter the user name and passworddefget_zhpwd (): F= Open ('pwd','R', encoding='Utf-8') Content= F.readline (). Split (' ')    returnContentflag=FalsedefLogin1 (func):defInner (*args,**Kwargs):GlobalFLAG" "Login" "        ifFLAG:Print("already logged in.") ret= Func (*args,**Kwargs)Else:            Print('Please enter user name and password, click Enter OK! ') Content=get_zhpwd () Zhanghao=Content[0] pwd= Int (content[1])            ifZhanghao = ='Wuhen'  andPWD = = 123: FLAG=TruePrint('Login Successful') ret= Func (*args,**Kwargs)Else:                Print('Logon Failure') FLAG=Falsereturninner@login1defceshi1 ():Print('I'm a number one .') @login1defceshi2 ():Print('I'm number second .') Ceshi1 () Ceshi2 ()

Python--------------Decorator Exercises

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.