# 1、文件操作
# day1.txt
# 1、文件路徑:E:\day1.txt
# 2、編碼方式:utf-8、gbk
# 3、操作方式:只讀,只寫,追加,讀寫,寫讀
# 以什么編碼方式儲存的方式儲存就以什么編碼方式打開
#絕對路徑
# f = open("E:\day1.txt",mode="r",encoding="gbk")
# count = f.read()
# print(count)
# f.close()
#相對路徑
# f = open("今天天氣真好",mode="r",encoding="utf-8")
# count = f.read()
# print(count,type(count))
# f.close()
# 只讀:r,rb(非文字類型文件,上傳,下載,圖片) bytes----str
# f = open("今天天氣真好",mode="rb")
# count = f.read()
# print(count,type(count))
# f.close()
#只寫:w
# 對於寫文件沒有此文件就會創建文件,
# f = open("今天天氣好",mode="w",encoding="utf-8")
# f.write("今天天氣好")
# f.close()
# 先將原文件內容全部刪除再寫
# f = open("今天天氣好",mode="w",encoding="utf-8")
# f.write("真的好呀")
# f.close()
#wb 文件默認什么編碼方式就以什么編碼方式寫進去
# f = open("今天天氣好",mode="wb")
# f.write("zhendeshi ".encode("utf-8"))
# f.close()
#追加 a 默認光標顯示在最后一個字符,只能進行追加不能
# f = open("今天天氣好",mode="a",encoding="utf-8")
# f.write("金額")
# f.close()
#ab
# f = open("今天天氣好",mode="ab")
# f.write("金額".encode("utf-8"))
# f.close()
#a+
# f = open("今天天氣好",mode="a+",encoding="utf-8")
# f.write("金額")
# f.seek(0)
# print(f.read())
# f.close()
#讀寫 r+ 先把原文件讀取出來,再寫入
# f = open("今天天氣真好",mode="r+",encoding="utf-8")
# print( f.read())
# f.write("yiyi,erer")
# f.close()
#以bytes類型讀寫
# f = open("今天天氣真好",mode="r+b")
# print( f.read())
# f.write("hahhahhahahhahahhahha".encode("utf-8"))
# f.close()
#寫讀 w+ 先清除原文件,再寫入
# f = open("今天天氣真好",mode="w+",encoding="utf-8")
# f.write("aaaaaaaaaaaaaaaaaaaaa")
# print(f.read())
# f.close()
#seek(調節光標)
# f = open("今天天氣真好",mode="w+",encoding="utf-8")
# f.write("bbbbaaaaaaaaaaaaaaaaaa")
# f.seek(1)
# print(f.read())
# f.close()
#功能詳解
# f = open("今天天氣真好",mode="r+",encoding="utf-8")
# # count = f.read(8) #讀出來的都是字符
# f.seek(3) #按字節定位光標位置,一個英文一個字節表示,一個中文三個字節表示
# count = f.read()
# print(count)
# f.close()
#斷點續傳 先定位光標位置,再調節光標位置
# tell (告訴你光標的位置)
# f = open("今天天氣真好",mode="r+",encoding="utf-8")
# f.write("哈哈哈哈")
# count = f.tell()
# f.seek(count-9)
# print(f.read())
# f.close()
#readline
# f = open("今天天氣真好",mode="r+",encoding="utf-8")
# line = f.readline() #一行一行的讀取
# print(line)
# f.close()
#readlines 每一行當成列表中的一個元素,添加到line列表中
# f = open("今天天氣真好",mode="r+",encoding="utf-8")
# line = f.readlines()
# print(line)
# f.close()
#truncate 截取一段讀取
# f = open("今天天氣真好",mode="r+",encoding="utf-8")
# f .truncate(4)
# f.close()
#同時打開多個文件
# with open("今天天氣真好",mode="r+",encoding="utf-8") as f :open("今天天氣好",mode="a",encoding="utf-8")as f1
# print(f.read(),f1.read()
#登錄注冊
username = input("用戶名:")
possword = input("密碼:")
with open("登錄",mode = "w",encoding="utf-8")as f:
f.write("{}\n{}".format(username,possword))
print("注冊成功")
list =[]
count = 0
while count < 3:
uname = input("輸入用戶名:")
pwd = input("請輸入密碼")
with open("登錄",mode = "r+",encoding="utf-8")as f1:
for line in f1:
list.append(line)
if uname == list[0].strip() and pwd ==list[1].strip():
print("登錄成功")
break
else:
count += 1
print("輸入錯誤")