staus = False with open('user', 'r') as f: user = f.readlines()[0].strip() f.seek(8) pawd = f.readlines()[1].strip() def login(inner): def console(*args, **kwargs): global staus ###調用global全局變量 若是此處不定義,由於下行定義了 staus,會報錯,而直接在上方定義 ##staus=False 就不能調用else if staus == False: username = input('your name is: ') passwd = input('your passwd is: ') print(user) print(pawd) if user == username.strip() and pawd == passwd.strip(): print('a') inner() staus = True else: print('The name or paswd is error!') else: inner() print('b') return console @login def home(): print('welcome to home') @login def book(): print('welcome to book') home() book()