
user_message={}
details=[]
i=0
try:
usertxt=open("usermessage.txt","r+")
except FileNotFoundError as f:
print(f,"this document has been broken or not exsist")
else:
list1=usertxt.readlines()
for one in list1:
device=one.split(":")
account,password=device[0],device[1].rstrip()
user_message[account]=password #载入用户的账户和密码
usertxt.close()
try:
detail_message=open("details.txt","r+")
except FileNotFoundError as n:
print(n,"user's details document has been broken or not exsist")
else:
scrach=detail_message.readlines()
for each in scrach:
each_r=each.split(":")
del each_r[-1]
each_load=[one.rstrip() for one in each_r]
details.append(each_load) #载入用户的详细信息
detail_message.close()
for count in details:
i+=1
for one in range(0,len(list(user_message.keys()))-i):
details.append([]) #同步长度
class User: #注册账号和设置密码
flag2=0
def __init__(self):
print("the original password is '111111'")
def set_account(self,account):
self.account=str(account)
if self.account not in user_message.keys():
user_message[self.account]="111111"
self.flag2+=1
else:
print("this account has exsisted!")
def set_password(self,password):
self.password=str(password)
user_message[self.account]=self.password
def landon(self,account,password):
account=str(account)
password=str(password)
if account in user_message.keys():
if password==user_message[account]:
print("you have landed on successfully!")
else:
print("sorry,the password you just inputed is wrong!")
else:
print("sorry,the account you have just inputed is wrong or doesn't exsist")
def change(self,account,password):
c_account=str(account)
c_password=str(password)
if c_account in user_message.keys():
user_message[c_account]=c_password
else:
print("this account don't exsist.")
def read(self,admin,password):
admin=str(admin)
password=str(password)
if admin=="admin" and password=="1234567890":
text=open("usermessage.txt","r")
content=text.read()
print(content)
text.close()
else:
print("you have no right to see.")
def save(self):
usertxt=open("usermessage.txt","w")
for key,value in user_message.items():
usertxt.write(key+":"+value+"n")
usertxt.close()
for lit in range(0,self.flag2):
details.append([])
self.flag2=0
class Details: #编辑用户详细信息
flag=4
def __init__(self):
print("please log_in firstly")
def set(self,name,ID,phone):
name=str(name)
ID=str(ID)
phone=str(phone)
if self.flag==1:
r_load=[name,ID,phone]
details[self.position]=r_load
else:
print("you didin't log in,please log in firstly")
def log_in(self,account,password):
account=str(account)
password=str(password)
if account in user_message.keys():
self.flag=0
if password==user_message[account]:
self.flag=1
self.position=list(user_message.keys()).index(account)
print("log in successfully,please continue")
else:
self.flag=2
print("your password is wrong")
else:
self.flag=3
print("this account is wrong or doesn't exsist")
def change_name(self,name):
name=str(name)
if self.flag==1 and details[self.position]:
details[self.position][0]=name
else:
return None
def change_ID(self,ID):
ID=str(ID)
if self.flag==1 and details[self.position]:
details[self.position][1]=ID
else:
return None
def change_phone(self,phone):
phone=str(phone)
if self.flag==1 and details[self.position]:
details[self.position][2]=phone
else:
return None
def save_details(self):
saver=open("details.txt","w")
for each in details:
for one in each:
saver.write(one+":")
saver.write("n")
saver.close()
self.flag=4
def read(self,admin,password):
admin=str(admin)
password=str(password)
if admin=="admin" and password=="1234567890":
text=open("details.txt","r")
content=text.read()
print(content)
text.close()
else:
print("you have no right to see.")
def read_all(admin,password):
admin=str(admin)
password=str(password)
if admin=="admin" and password=="1234567890":
list1=list(user_message.items())
list2=details
m=0
for one,two in list1:
string=''
if list2[m]:
string+=("Name:"+list2[m][0]+" "+"ID:"+list2[m][1]+" "+"Phone:"+list2[m][2])
print("Account:"+one+" "+"Password:"+two," ",string)
m+=1 #浏览所有信息
新手上路,多多指教!