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