lock_file = open('C:\\aaaaaaaaaaaaa\\ccc.txt','r+') ###以可读可写的方式打开文件,如果打开后先读过一次文件,则写文件是以追加的方式写的
lock = lock_file.read().split("\n") ###读文件,并按照换行符将文件分隔开,存在列表中
print (lock)
with open('C:\\aaaaaaaaaaaaa\\bbb.txt') as f: ###以with方式打开的文件,不需要再进行close
l = f.read().split("\n")
while (1):
count = 0
usrname = input("please input username:")
tt = list(filter(lambda x: usrname in x, lock)) ###判断lock列表中,每一个元素,是否都满足lambda函数
print(tt)
t = list(filter(lambda x: usrname in x.split(":"), l))
print(t)
if (tt):
print ("this user is already locked")
elif (t):
while count<3:
password = input("please input password:")
p = list(filter(lambda x: password in x.split(":"), t))
if (p):
print("yanzhengtongguo")
break
else:
count +=1
else:
print("locked")
lock_file.write(usrname + "\n")
elif usrname == "q":
break
else:
print("username not exit,please try again")
lock_file.close()

浙公网安备 33010602011771号