Python ----- simple simulation blog landed Park

def userpw(set_name):
userpw_dic={}
with open(set_name,mode='r+',encoding='utf-8') as f:
for line in f:
username, password = line.strip().split('|')
userpw_dic[username] = password
return userpw_dic

Registered DEF ():
Time =. 3
userpw_dic userpw = ( 'userpw_dic.txt')
the while Time> 0:
username = INPUT ( 'Enter account (letters and numbers) >>>') Strip ().
password = INPUT ( ' Please enter a password (length between 14 ~. 6) >>> ') Strip ().
IF username.isalnum () and (. 6 <= len (password) <= 14) and (Not in userpw_dic username):
with Open ( 'userpw_dic.txt', MODE = '+ A', encoding = 'UTF-. 8') AS F:
f.write (F '{username} | {} password \ n-')
Print ( 'registration success')
return True
Time - =. 1
Print (F 'registration fails, the number of times you have {time}')
Print ( 'registration fails, exit the program')
return False

the Login DEF ():
IF status_dic:
Print ( 'Account login, log off the account before attempting!')
the else:
Time = 3
userpw_dic = userpw ( 'userpw_dic.txt')
the while Time> 0:
username = the INPUT ( ' Please enter the account (letters and numbers) >>> '). Strip ()
password = iNPUT (' enter the password (the length between 14 ~. 6) >>> '). Strip ()
IF userpw_dic.get (username) password ==:
status_dic [username] = True
Print ( 'successful landing')
return True
Time - 1 =
Print (f 'failed on landing, the number of times you have {time}')
Print ( 'login failed, exiting!')
return False

def wrapper(func):
def inner():
if status_dic:
func([i for i in status_dic][0])
else:
print('请用户先登陆')
if login():
func([i for i in status_dic][0])
else:
return False
return inner

@wrapper
DEF Article This article was (name):
Print (f 'Welcome {name} enter the article page!')
the while 1:
[1. 2. Import content directly write files 3. Exit md article page] num = input ( 'Please select : '.) Strip ()
IF NUM ==' 1 ':
essay_content the iNPUT = (' Please enter [filename | file contents] >>> ') Strip ().
Essay, cotent = essay_content.split (' | ', . 1)
with Open (Essay, MODE = 'W', encoding = 'UTF-. 8') AS F:
f.write (cotent)
Print ( 'successfully written!')
elif NUM == '2':
Essay = INPUT ( 'enter the path to the file md >>>') Strip ().
the try:
with Open (Essay, MODE = 'R & lt', encoding = 'UTF-. 8') AS F1, Open (essay.split ( '.' ) [0] + '.txt', MODE = 'W', encoding = 'UTF-. 8') AS F2:
for Line in F1:
F2.Write (Line)
Print ( "successful introduction ')
the except FileNotFoundError:
Print (' this path does not exist Please reenter! ')
NUM == elif '3':
BREAK
the else:
Print ( 'input errors, please re-enter!')

@wrapper
DEF at discuss (name):
Print (f 'Welcome {name} Enter comments page!')

@wrapper
DEF Diary (name):
Print (f 'Welcome {name} into the diary page!')

@wrapper
DEF the collect (name):
Print (f 'Welcome {name} into the Favorites page!')

@wrapper
DEF Zimbabwe Logout (name):
status_dic.clear ()
Print (F '{name} login status is logged off!')

status_dic = {}
funcs = {. 1: Login, 2: Registered,. 3: Article This article was,. 4: at discuss,. 5: Diary,. 6: the collect,. 7: Zimbabwe Logout}
the while True:
.. Print ( '. 1 login \ n2 Register ...... \ n3 enter the article page \ n4 into the comment page \ n5 into the diary page \ n6 into the Favorites page \ n7 cancellation account \ n8 quit the whole program ')
NUM = the iNPUT (' Please enter your choice: ') .strip ()
IF num.isdecimal () and 0 <int (NUM) <. 8:
RET = funcs int (NUM)
IF RET == False:
BREAK
elif NUM == '. 8':
Print ( 'exiting the program!' )
BREAK
the else:
Print ( 'input is incorrect, please re-enter!')

Guess you like

Origin www.cnblogs.com/hql1117/p/11106525.html