import sys
account_file = "user_file"
locked_file = "lock_file"
def deny_account(username):
print("您的用户已经被锁定!")
with open(locked_file,"a") as deny_f:
deny_f.write("\n" + username)
def main():
retry_count = 0
retry_limit = 3
while retry_count < retry_limit:
username = input("\033[32:lm请输入用户名:\033[om")
with open(locked_file,"r") as lock_f:
#采用with的文件打开方式,防止忘记f.close()关闭文件
"""
lines = []
for line in lock_f.readlines():
lines.append(line.strip())
if username in lines:
"""
for line in lock_f.readlines():
if len(line) == 0:
continue
if username == line.strip():
sys.exit("\033[32:lm用户 %s 已经被锁定!\033[0m" %username)
if __name__ == "__main__":
main()