1 ImportGetpass,sys2u=03 whileu< 3:4user_name = input ('Please input your name:')5 #user_passwd = getpass.getpass (' Please input ' password: ')6Lock_file = open ('c:/installation package/pycharm/day01/user_lock.txt','r+')7Lock_line =Lock_file.readlines ()8 forLockinchLock_line:9User_lock = Lock.strip ('\ n')Ten ifUser_name = =User_lock: One #print ('%s is lock! '% user_name) ASys.exit ('%s is lock!'%user_name) -List_file = open ('c:/installation package/pycharm/day01/user_list.txt','R') -List_line =List_file.readlines () the forListinchList_line: -(user_list,passwd_list) = List.strip ('\ n'). Split () - ifUser_name = =user_list: -i =0 + whileI < 3: -USER_PASSWD = Getpass.getpass ('Please input password:') + ifUSER_PASSWD = =passwd_list: ASys.exit ('%s Welcome to www.hao123.com'%user_name) at Print('Please enter again!') -i + = 1 - Else: -Lock_file.write (user_name+'\ n') -Sys.exit ('sorry,%s is locking. Administrator') - #print (' Sorry,%s not exsit! ') in list_file.close () - lock_file.close () toU + = 1 +Sys.exit ('INPUT Error!!!')
####
Absolute path under 1.windows:
Windows can read a file with \, but inside the string \ is used as an escape character, then Python has two ways of describing the path:' D:\\a.txt ', the escaped way;R ' D:\a.txt ', declaring that the string does not need to be escaped
C:\Users\Administrator\Desktop\python\t1.txt This path will be an absolute error, because \ t is escaped, and Python resolves to C:\Users\Administrator\Desktop\ Python 1.txt is sure to make an error at this time. If you change to the "c:/users/administrator/desktop/python/t1.txt" writing will not be an error (recommended to use this "/", you can avoid a lot of exceptions). 2.open file, close is required, otherwise there will be a case where editing the file cannot be saved 3.
\ is escaped meaning, ' \ n ' is a newline, ' \ t ' is tab, ' \ \ ' is \
4. File stitching, or +
5.format Output:%s string,%d integer%f floating point%x hexadecimal
Python Learning Note 1: User Login