python_文件的处理
来源:互联网 发布:日本美国动画 知乎 编辑:程序博客网 时间:2024/05/19 14:50
import osdef deluser(username): ''' 删除用户名 :param username: :return: ''' with open('db.text','r') as f1 : lines = [] is_user=user_exist(username) print(is_user) if is_user: for line in f1: line1 = line.strip() line_list = line1.split('$') if username == line_list[0]: continue else: lines.append(line) open('db.text', 'w').writelines(lines)def login(username,pwd): ''' 用户名密码登陆判断 :param username: 用户名 :param pwd: 密码 :return: True 登陆成功 False 登录失败 ''' with open('db.text') as user_pwd: for line in user_pwd: line=line.strip() longinlist=line.split("$") if username==longinlist[0] and pwd==longinlist[1]: return True return Falsedef register(username,pwdword): ''' 注册用户 :param username: :param pwdword: :return: ''' with open('db.text','a') as f: f.write('\n'+username+'$'+pwdword)def user_exist(username): ''' 判断用户名是否存在 :param username: :return: ''' with open('db.text') as f: for line in f: line = line.strip() line_list = line.split('$') if line_list[0] == username: return True return Falseprint('欢迎登陆')inp=int(input("1:登陆 2:注册"))if inp==1: username=input('请输入用户名') pwd=input('请输入密码') is_login=login(username,pwd) if is_login: print("登陆成功") else: print("登陆失败")elif inp == 2: username = input('请输入用户名') if user_exist(username): print("已经注册过了") else: pwd = input('请输入密码') register(username,pwd) print('注册成功')elif inp == 3: username = input('请输入用户名') deluser(username)
阅读全文
0 0
- python_文件的处理
- python_文件处理
- python_文件的读取
- python_文件的读写
- python_文件的copy
- python_文件的赋值
- Python_批量修改文件的编码格式
- 21-python_异常处理
- python_异常处理
- python_时间处理
- Python_文件操作
- python_文件操作
- python_创建xml文件
- Python_文件异常
- python_处理输入异常技巧
- Python_使用csv模块解析csv文件(处理Excel表格)
- python_类的继承
- Python_类的继承
- 数据库第十七周学习攻略
- springMVC登录验证码
- 数论——组合数(基础)
- Spring MVC
- tableView 的cell不铺满整个屏幕时,下面多余分割线消失处理
- python_文件的处理
- 记忆化搜索:POJ1579-Function Run Fun(最基础的记忆化搜索)
- 关于BASIS_MOLOPT以及BASIS_MOLOPT_UCL基组的说明
- 因式分解梳理
- php数组array_merge例子
- complex类
- HTTP请求的GET与POST方式的区别
- 数据库第八周学习攻略(第十组)
- 2017.7.12 C组总结