python read the file data to achieve a simple registration operation

! # / usr / bin / env Python 
# - * - Coding: UTF-8 - * -
# @time: 2019-11-21 14:32
# @ Player: zhaohq
# @email: [email protected]
# @file : zhuc.py
name = INPUT ( 'name:')
with Open ( 'zhuc.txt', 'A') AS FO:
with Open ( 'zhuc.txt', 'R & lt') AS FO:
Data = fo.readlines () # read information to the data
COUNT data .__ len = __ () # calculates data amount of data
I = 0
the while I <COUNT:
with Open ( 'zhuc.txt', 'R & lt') AS fo1 of:
data = fo1.readlines ( ) # read information to the data
COUNT data .__ len = __ () # calculates data amount of data
str1 = data [I]
str2 str1 = [: str1.rfind ( '\ T')] # reads the user name
if name == str2 :
print ( 'username already registered, please enter a different user name')
name = input('name:')
i = 0
continue
else:
i = i+1
continue
else:
password = input('password')
with open('zhuc.txt', 'a') as fo:
fo.writelines([name, '\t', password, '\n'])
print('注册成功')

Guess you like

Origin www.cnblogs.com/LoongUncle/p/11906422.html