python读取文件数据实现简单的注册操作

Posted loonguncle

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python读取文件数据实现简单的注册操作相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019-11-21 14:32
# @ player :zhaohq
# @Email : 909095763@qq.com
# @File : zhuc.py
name = input(‘name:‘)
with open(‘zhuc.txt‘, ‘a‘) as fo:
with open(‘zhuc.txt‘, ‘r‘) as fo:
data = fo.readlines() # 读取信息到data
count = data.__len__() # 计算data数据量
i = 0
while i < count:
with open(‘zhuc.txt‘, ‘r‘) as fo1:
data = fo1.readlines() # 读取信息到data
count = data.__len__() # 计算data数据量
str1 = data[i]
str2 = str1[:str1.rfind(‘ ‘)] # 读取用户名
if name == str2:
print(‘用户名已注册,请输入其他用户名‘)
name = input(‘name:‘)
i = 0
continue
else:
i = i+1
continue
else:
password = input(‘password‘)
with open(‘zhuc.txt‘, ‘a‘) as fo:
fo.writelines([name, ‘ ‘, password, ‘ ‘])
print(‘注册成功‘)

以上是关于python读取文件数据实现简单的注册操作的主要内容,如果未能解决你的问题,请参考以下文章

对fs异步读取文件的理解

用python实现读写文件常见操作方式

xlrd实现从excel文件读取数据

python的文件操作读取内容替换

Python实现用户注册到文件

ruby读取csv文件数据