1. 程式人生 > >文件操作,是一個存為字符串格式的登陸系統,有增刪改查的功能,但不是我想要的。。。

文件操作,是一個存為字符串格式的登陸系統,有增刪改查的功能,但不是我想要的。。。

str repl 修改 blog 一個 ice body pwd 刪除

def register(NAME, PWD, TEL):
    with open(userdate.txt, a, encoding=utf-8) as f:
        new = &&.join([NAME, PWD, TEL])
        f.write(\n + str(new))
    return True


def same(NAME):
    with open(userdate.txt, r, encoding=utf-8) as f:
        for i in f:
            name 
= i.split(&&)[0] if name == NAME: return True return False def login(NAME, PWD): with open(userdate.txt, r, encoding=utf-8) as f: for i in f: if NAME == i.split(&&)[0] and PWD == i.split(&&)[1]:
return True return False def change(NAME, TEL): with open(userdate.txt, r, encoding=utf-8) as f: new = ‘‘ for i in f: if NAME == i.split(&&)[0] and TEL == i.split(&&)[2]: newpwd = input(輸入新的密碼) i = i.replace(i.split(
&&)[1], newpwd) new += i # else: # main() with open(userdate.txt, w, encoding=utf-8) as f: f.write(new) return True def delete(NAME, PWD): with open(userdate.txt, r, encoding=utf-8) as f: new = ‘‘ for i in f: if NAME == i.split(&&)[0] and PWD == i.split(&&)[1]: i = \n new += i with open(userdate.txt, w, encoding=utf-8) as f: f.write(new) return True def main(): print(1:註冊,2:登錄,3:變更,4:刪除) choice = input(請選擇).strip() if choice == 1: NAME = input(輸入用戶名).strip() if same(NAME): print(用戶名已被占用,重新輸入) main() else: PWD = input(輸入密碼).strip() TEL = input(輸入電話).strip() if register(NAME, PWD, TEL): print(註冊成功) if choice == 2: NAME = input(輸入用戶名).strip() PWD = input(輸入密碼).strip() if login(NAME, PWD): print(登錄成功) if choice == 3: NAME = input(輸入用戶名).strip() TEL = input(輸入電話).strip() if change(NAME, TEL): print(修改成功) if choice == 4: NAME = input(輸入用戶名).strip() PWD = input(輸入密碼).strip() if delete(NAME, PWD): print(刪除成功) else: main() main()

文件操作,是一個存為字符串格式的登陸系統,有增刪改查的功能,但不是我想要的。。。