Python Learning Note 1: User Login

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.