def renzheng(func): # Higher-order functions pass the function name func as a parameter def wrapper(*args,** kwargs): username =input( ' Username: ' ).strip() passwd=input('密码:').strip() if username=='qwe' and passwd=='123': res = func(*args,** kwargs) return res else : print ( ' error ' ) return wrapper
@renzheng #Decorator def index (): print ( ' Welcome to the homepage ' ) home( " Little Li " )#Execute the home function after executing the authentication function once
@renzheng def home(name): print ( ' Welcome home %s ' % name) shop( " Xiao Wang " ) #Execute the shop function after executing the authentication function once
@renzheng
def shop(name): print ( ' %s has %s in the shopping cart, %s ' %(name, ' milk tea ' , ' sister ' ))
index() #Execute the index function after executing the authentication function once
index()
home()
shop()