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

