Application python file read write Login Register

! # / usr / bin / python3 
# - * - Coding: UTF-8 - * -
# Author: ZHW
# read the file contents
: def open_file (filename, file_type, * args)
data # read the file
if == FILE_TYPE 'R & lt':
flie_list = []
with Open (filename, FILE_TYPE), sub_ALL AS:
for file_line in, sub_ALL:
flie_list.append (file_line.strip ())
#Print (flie_list)
return flie_list
# read user file No.
elif FILE_TYPE == 'Ru':
flie_list = []
with Open (filename, 'R & lt'), sub_ALL AS:
for file_line in, sub_ALL:
file_l = file_line.split ( '|')
user_no file_l = [0]
flie_list.append (user_no.strip ())
#Print (flie_list)
return flie_list
# write file
elif FILE_TYPE == '+ A':
Data = args [0]
with Open (filename, FILE_TYPE), sub_ALL AS:
sub_all.write (Data + "\ the n-")
the else:
Print ( 'format you entered is not, check')

class the User (Object):
DEF __init __ (Self, user_no, user_pw):
self.user_no = user_no
self.user_pw = user_pw
self.file = 'login.log'
the @Property
# check whether the account already exists
DEF check_user (Self):
flie_list = OPEN_FILE (self.file, 'ru')
iF self.user_no in flie_list:
return '. 1'
the else:
return '0'
# registered account
DEF REGIST (Self):
USER_INFO = '% S | S%'% (self.user_no, self.user_pw)
OPEN_FILE (self.file, '+ A', USER_INFO)
#return 'registered successfully'
# account login
DEF the Login (Self):
flie_list = OPEN_FILE (self.file, 'r')
user_info = '% S | S%'% (self.user_no, self.user_pw)
IF user_info in flie_list :
return '1'
the else:
return '0'


DEF return_more (args):
Pass

# sign in the cycle validation, circulation registered account
the while True:
Print ( 'select \ the n-'
'1.Registration \ n '
' 2. Log \ n '
Too many incorrect you entered, exited! ')


















the Choose == elif '2':
for I in Range (. 3):
user_no = INPUT ( 'Enter login account:') Strip ().
user_pw = INPUT ( 'Enter Password') .strip ()
User = the User (user_no, user_pw)
# user login
return_mk = user.login ()
IF return_mk == '0':
Print ( "Login failed, please re-enter")
the else:
Print ( 'Login successful')
BREAK
elif the Choose == '3 ':
BREAK
the else:
Print ( "Have input number, please re-enter")

Guess you like

Origin www.cnblogs.com/hong1227/p/11570564.html