码迷,mamicode.com
首页 > 其他好文 > 详细

文件操作,是一个存为字符串格式的登陆系统,有增删改查的功能,但不是我想要的。。。

时间:2018-02-06 14:59:22      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:文件   reg   pen   color   class   with   ret   rda   amp   

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()

 

文件操作,是一个存为字符串格式的登陆系统,有增删改查的功能,但不是我想要的。。。

标签:文件   reg   pen   color   class   with   ret   rda   amp   

原文地址:https://www.cnblogs.com/xusuns/p/8422266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!