nickkkkkkk

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

 

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()

posted on 2018-04-25 10:25  nickkkkkkk  阅读(90)  评论(0)    收藏  举报