python應(yīng)用文件讀取與登錄注冊功能
python應(yīng)用文件讀取與登錄注冊功能,具體實(shí)現(xiàn)代碼如下所示:
#!/usr/bin/python3 # -*- coding: utf-8 -*- # Author: zhw #讀取文件中的內(nèi)容 def open_file(filename ,file_type , *args): #讀取文件中的數(shù)據(jù) if file_type == 'r': flie_list = [] with open(filename,file_type) as sub_all: for file_line in sub_all: flie_list.append(file_line.strip()) #print(flie_list) return flie_list #讀取文件中的用戶號 elif file_type == 'ru': flie_list = [] with open(filename,'r') as sub_all: 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 #寫入文件 elif file_type == 'a+': data = args[0] with open(filename, file_type) as sub_all: sub_all.write(data +"\n") else: print('您輸入的格式?jīng)]有,請檢查') class User(object): def __init__(self, user_no, user_pw): self.user_no = user_no self.user_pw = user_pw self.file = 'login.log' @property #檢查賬號是否已經(jīng)存在 def check_user(self): flie_list = open_file(self.file, 'ru') if self.user_no in flie_list: return '1' else: return '0' #注冊賬號 def regist(self): user_info = '%s|%s' % (self.user_no, self.user_pw) open_file(self.file, 'a+',user_info) #return'注冊成功' #賬號登錄 def 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' else: return '0' def return_more(args): pass #循環(huán)驗(yàn)證登錄,循環(huán)注冊賬號 while True: print('請選擇\n ' '1. 注冊\n' '2. 登錄\n' '3. 退出') choose = input('請選擇').strip() if choose == '1': for i in range(3): user_no = input('請輸入注冊賬號:').strip() user_pw = '' user = User(user_no,user_pw) #檢查用戶號是否存在 return_more = user.check_user if return_more == '0': user_pw = input('請輸入注冊密碼:').strip() user = User(user_no, user_pw) return_more = user.regist() print(return_more) break else: print('您輸入的賬號已經(jīng)存在,請選擇其他賬號') #print('您輸入的錯誤次數(shù)太多,已退出!') elif choose == '2': for i in range(3): user_no = input('請輸入登錄賬號:').strip() user_pw = input('請輸入登錄密碼').strip() user = User(user_no, user_pw) #用戶登錄 return_mk = user.login() if return_mk =='0': print("登錄失敗,請重新輸入") else: print('登錄成功') break elif choose == '3': break else: print('輸入序號有無,請重新輸入')
總結(jié)
以上所述是小編給大家介紹的python應(yīng)用文件讀取與登錄注冊功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
- 用Python實(shí)現(xiàn)web端用戶登錄和注冊功能的教程
- Python實(shí)現(xiàn)注冊登錄系統(tǒng)
- Python登錄注冊驗(yàn)證功能實(shí)現(xiàn)
- Python實(shí)現(xiàn)注冊、登錄小程序功能
- Python制作簡易注冊登錄系統(tǒng)
- Python +Selenium解決圖片驗(yàn)證碼登錄或注冊問題(推薦)
- python實(shí)現(xiàn)登錄與注冊系統(tǒng)
- Python3 Tkinkter + SQLite實(shí)現(xiàn)登錄和注冊界面
- Python?+?Tkinter連接本地MySQL數(shù)據(jù)庫簡單實(shí)現(xiàn)注冊登錄
- Python實(shí)現(xiàn)用戶登錄注冊
相關(guān)文章
python 系統(tǒng)調(diào)用的實(shí)例詳解
這篇文章主要介紹了python 系統(tǒng)調(diào)用的實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-07-07python實(shí)現(xiàn)將range()函數(shù)生成的數(shù)字存儲在一個列表中
這篇文章主要介紹了python實(shí)現(xiàn)將range()函數(shù)生成的數(shù)字存儲在一個列表中,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04對python實(shí)現(xiàn)二維函數(shù)高次擬合的示例詳解
今天小編就為大家分享一篇對python實(shí)現(xiàn)二維函數(shù)高次擬合的示例詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12Python Flask利用SocketIO庫實(shí)現(xiàn)圖表的繪制
這篇文章主要為大家詳細(xì)介紹了Python Flask框架如何利用SocketIO庫實(shí)現(xiàn)圖表的繪制,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起了解一下2022-12-12Python中break語句和continue語句的用法講解
在Python中,break語句和continue語句一般用于循環(huán)語句中,這篇文章主要介紹了Python中break語句和continue語句的用法小結(jié),需要的朋友可以參考下2022-12-12