#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: zhw
#读取文件中的内容
def open_file(filename ,file_type , *args):
#读取文件中的数据
if file_type == 'r':
flie_list = []
with open(filename,file_type) as sub_all:
for file_line in sub_all:
flie_list.append(file_line.strip())
#print(flie_list)
return flie_list
#读取文件中的用户号
elif file_type == 'ru':
flie_list = []
with open(filename,'r') as sub_all:
for file_line in sub_all:
file_l = file_line.split('|')
user_no = file_l[0]
flie_list.append(user_no.strip())
#print(flie_list)
return flie_list
#写入文件
elif file_type == 'a+':
data = args[0]
with open(filename, file_type) as sub_all:
sub_all.write(data +"\n")
else:
print('您输入的格式没有,请检查') class User(object):
def __init__(self, user_no, user_pw):
self.user_no = user_no
self.user_pw = user_pw
self.file = 'login.log'
@property
#检查账号是否已经存在
def check_user(self):
flie_list = open_file(self.file, 'ru')
if self.user_no in flie_list:
return '1'
else:
return '0'
#注册账号
def regist(self):
user_info = '%s|%s' % (self.user_no, self.user_pw)
open_file(self.file, 'a+',user_info)
#return'注册成功'
#账号登录
def login(self):
flie_list = open_file(self.file, 'r')
user_info = '%s|%s' % (self.user_no, self.user_pw)
if user_info in flie_list:
return '1'
else:
return '0' def return_more(args):
pass #循环验证登录,循环注册账号
while True:
print('请选择\n '
'1. 注册\n'
'2. 登录\n'
'3. 退出')
choose = input('请选择').strip()
if choose == '1': for i in range(3):
user_no = input('请输入注册账号:').strip()
user_pw = ''
user = User(user_no,user_pw)
#检查用户号是否存在
return_more = user.check_user
if return_more == '0':
user_pw = input('请输入注册密码:').strip()
user = User(user_no, user_pw)
return_more = user.regist()
print(return_more)
break
else:
print('您输入的账号已经存在,请选择其他账号')
#print('您输入的错误次数太多,已退出!')
elif choose == '2':
for i in range(3):
user_no = input('请输入登录账号:').strip()
user_pw = input('请输入登录密码').strip()
user = User(user_no, user_pw)
#用户登录
return_mk = user.login()
if return_mk =='0':
print("登录失败,请重新输入")
else:
print('登录成功')
break
elif choose == '3':
break
else:
print('输入序号有无,请重新输入')

python应用文件读取写登录注册的更多相关文章

  1. Python编码/文件读取/多线程

    Python编码/文件读取/多线程 个人笔记~~记录才有成长   编码/文件读取/多线程 编码 常用的一般是gbk.utf-8,而在python中字符串一般是用Unicode来操作,这样才能按照单个字 ...

  2. python大文件读取

    python大文件读取 https://stackoverflow.com/questions/8009882/how-to-read-a-large-file-line-by-line-in-pyt ...

  3. Python: 读文件,写文件

    读写文件是最常见的IO操作.Python内置了读写文件的函数. 读写文件前,我们先了解一下,在磁盘上读写文件的功能都是有操作系统提供的,现代操作系统不允许普通的程序直接操作磁盘,所以,读写文件就是请求 ...

  4. python .dcm文件读取,并转化为.jpg格式

    .dcm文件是DICOM(Digital Imaging and Communications in Medicine)即医学数字成像和通信中记录医学图像和相关信息的文件,在用于医学图像处理的时候我们 ...

  5. python 用装饰器写登录

    # 1.编写装饰器,为多个函数加上认证的功能(用户的账号密码来源于文件), # 要求登录成功一次,后续的函数都无需再输入用户名和密码 # FLAG = False # def login(func): ...

  6. 微信小程序开发:python+sanic 实现小程序登录注册

    开发微信小程序时,接入小程序的授权登录可以快速实现用户注册登录的步骤,是快速建立用户体系的重要一步.这篇文章将介绍 python + sanic + 微信小程序实现用户快速注册登录全栈方案. 微信小程 ...

  7. Python txt文件读取写入字典的方法(json、eval)

    link:https://blog.csdn.net/li532331251/article/details/78203438 一.使用json转换方法 1.字典写入txt import json d ...

  8. python tips:文件读取——换行符的问题

    问题:在windows系统中,换行的符号是'\r\n'.python在读文件的时候为了系统兼容,会默认把'\r','n','\r\n'都视作换行.但是在windows文件中,可能在同一行中同时存在'\ ...

  9. 用python实现文件读取和内容替换

    infile = open("D:/test.txt", "r") #打开文件 outfile = open("D:/pp2.txt", & ...

随机推荐

  1. TokuDB安装

    安装TokuDB 1, 创建mysql数据目录 #顺便把临时目录创建好 mkdir -p /data/mysql/tmp groupadd -r mysql useradd -g mysql -r - ...

  2. 2-sat——暴力染色输出方案hdu1814

    因为要求输出字典序最小的解,所以用暴力染色 具体有点像二分图染色 遍历0-2*n-1个点,尝试将每个点染成1,该点所能到达的所有点都要染成1 如果不行,则把上该点的影响消除,再把对立点染成1,如果还不 ...

  3. 微信公众号 SVG长按互动

    <section class="" style="display: block;width: 100%;height:667px;overflow:hidden;m ...

  4. iscroll 上拉加载和下拉刷新

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...

  5. light oj 1095 组合数学

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> ...

  6. vue2 + koa2全栈部署

    1.首先打包前端上传 修改config下的index.js 代理地址为服务器IP index: path.resolve(__dirname, '../dist/index.html'), asset ...

  7. google移动版针对智能手机、非智能手机的蜘蛛的User-agent

    非智能手机蜘蛛的User-agent有以下两个 SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2. ...

  8. pymysql 使用

    适用环境 python版本 >=2.6或3.3 mysql版本>=4.1 安装 可以使用pip安装也可以手动下载安装. 使用pip安装,在命令行执行如下命令: 1 pip install  ...

  9. Leetcode961. N-Repeated Element in Size 2N Array重复N次的元素

    在大小为 2N 的数组 A 中有 N+1 个不同的元素,其中有一个元素重复了 N 次. 返回重复了 N 次的那个元素. 示例 1: 输入:[1,2,3,3] 输出:3 示例 2: 输入:[2,1,2, ...

  10. html常用标签详解3-a标签

    a标签 1.a标签的属性 a标签属于行内元素标签,双标签<a></a> href:a标签的跳转地址 target:打开方式(_self自身:_blank:新窗口) title: ...