用户的配置文件如下

backend oldboy
school school1 age 21 weight 210
qq 550176565 iphone 139987676
backend oldgirl
school school2 age 22 weight 220
backend oldteacher
school school3 age 23 weight 230
backend oldstudent
school school4 age 24 weight 240

作业要求:

1、实现查询用户信息

2、实现增加用户信息

3、实现删除用户信息

#Auther Bob
#--*--conding:utf-8 --*--
name_list = []
tmp_list = []
info_list = []
f = open("homeworkdb","r",encoding="utf-8")
for line in f:
if line.startswith("backend"):
tmp_list = (line.strip().split(" "))
# name_list.append(tmp_list[1])
# print(tmp_list)
name_list.append(tmp_list[1]) f.close()
flag = 0
# print(name_list)
while True:
option = int(input("1:查询用户信息\n2:删除用户信息\n3:增加用户信息\n4:退出\n"))
if option == 1:
name = input("please input name:")
if name in name_list:
with open("homeworkdb","r",encoding="utf-8") as f:
for line in f:
if flag == 0 and line.strip() == "backend " + name:
flag = 1
continue
if flag == 1 and not line.startswith("backend"):
info_list.append(line.strip())
if flag == 1 and line.startswith("backend"):
flag = 0
continue
print("%s的信息是:" %(name))
for info in info_list:
print(info)
info_list = []
else:
print("%s is not in list" %(name))
continue
elif option == 2:
name = input("please in name:")
if name in name_list:
with open("homeworkdb","r",encoding="utf-8") as f1,open("tmp","w",encoding="utf-8") as f2:
for line in f1:
if flag == 0 and line.strip() == "backend " + name:
flag = 1
continue
if flag == 1 and not line.startswith("backend"):
continue
if flag == 1 and line.startswith("backend"):
flag = 0
if flag == 0:
f2.write(line)
with open("homeworkdb","w",encoding="utf-8") as f1,open("tmp","r",encoding="utf-8") as f2:
for line in f2:
f1.write(line)
name_list.remove(name)
with open("homeworkdb","r",encoding="utf-8") as f1,open("tmp","w",encoding="utf-8") as f2:
for line in f1:
if line == "\n":
continue
else:
f2.write(line) with open("tmp","r",encoding="utf-8") as f1,open("homeworkdb","w",encoding="utf-8") as f2:
for line in f1:
f2.write(line)
else:
print("%s is not in list" %(name))
continue
elif option == 3:
name = input("please in name:")
if name in name_list:
print("%s is in list" % (name))
info = input("please input %s is information" % (name))
with open("homeworkdb" ,"r",encoding="utf-8") as f1:
for line in f1:
if flag == 0 and line.strip() == "backend " + name:
flag = 1
continue
if flag == 1 and not line.startswith("backend"):
info_list.append(line.strip())
if flag == 1 and line.startswith("backend"):
flag = 0
continue
# print(info_list)
if info in info_list:
print("%s is already exist" %(info ))
else:
with open("homeworkdb","r",encoding="utf-8") as f1,open("tmp","w",encoding="utf-8") as f2:
flag = 0
for line in f1:
# print(flag)
if flag == 0 and line.strip() == "backend " + name:
f2.write(line)
tmp_info =" " + info + "\n"
f2.write(tmp_info)
else:
f2.write(line)
with open("tmp","r",encoding="utf-8") as f1,open("homeworkdb","w",encoding="utf-8") as f2:
for line in f1:
f2.write(line)
else:
print("%s is not in list" %(name))
info = input("please input %s is information" % (name))
with open("homeworkdb","a",encoding="utf-8") as f1:
s1 = "\n" + "backend " + name
s2 = "\n" + " " + info
f1.write(s1)
f1.write(s2)
name_list.append(name)
elif option == 4:
exit()
else:
print("invalid input,please input[1|2|3|4]")
continue

  

 

  

python作业之修改用户配置文件的更多相关文章

  1. python作业day3修改配置文件

    思维还有点乱,撸代码到深夜,先上代码吧.(我是跟着武sir的思路的) 流程图: 代码(有注释): #!/usr/bin/env python # -*- coding:utf-8 -*- import ...

  2. python读写增删修改ini配置文件

    一,百度百科 .ini 文件是Initialization File的缩写,即初始化文件,是windows的系统配置文件所采用的存储格式,统管windows的各项配置,一般用户就用windows提供的 ...

  3. xp默认安装路径及本地用户配置文件存放路径修改

    xp默认安装路径及本地用户配置文件存放路径修改 修改注册表可能会造成您的系统崩溃或数据丢失,请先行备份操作系统,以备不测!!! 备份注册表步骤: 1.在“桌面”上按快捷键“Ctrl+R”,调出“运行” ...

  4. python作业学员管理系统(第十二周)

    作业需求: 用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下 讲师视图 管理班级,可创建班级,根据学员qq号把学员加入班级 可创建指定班级的上课纪录,注意一节上课纪录对应多条学 ...

  5. python作业堡垒机(第十三周)

    作业需求: 1. 所有的用户操作日志要保留在数据库中 2. 每个用户登录堡垒机后,只需要选择具体要访问的设置,就连接上了,不需要再输入目标机器的访问密码 3. 允许用户对不同的目标设备有不同的访问权限 ...

  6. Python作业-选课系统

    目录 Python作业-选课系统 days6作业-选课系统: 1. 程序说明 2. 思路和程序限制 3. 选课系统程序目录结构 4. 测试帐户说明 5. 程序测试过程 title: Python作业- ...

  7. python作业ATM(第五周)

    作业需求: 额度 15000或自定义. 实现购物商城,买东西加入 购物车,调用信用卡接口结账. 可以提现,手续费5%. 支持多账户登录. 支持账户间转账. 记录每月日常消费流水. 提供还款接口. AT ...

  8. kafka实战教程(python操作kafka),kafka配置文件详解

    kafka实战教程(python操作kafka),kafka配置文件详解 应用往Kafka写数据的原因有很多:用户行为分析.日志存储.异步通信等.多样化的使用场景带来了多样化的需求:消息是否能丢失?是 ...

  9. 【HOW】用PowerShell脚本修改用户配置文件属性显示次序

    首先将如下脚本保存为PowerShell文件,如:ReorderUserProfileProperty.ps1. 在执行此脚本时,如果不输入任何参数,将列出所有用户配置文件属性的名称和显示次序:如果只 ...

随机推荐

  1. shell 1基础

    shell简介 shell是一个用C语言编写的程序,是用户使用Linux的桥梁.shell既是一种命令语言,又是一种程序设计语言. shell脚本(shell script),是一种为shell编写的 ...

  2. Microsoft Enterprise Library

    http://entlib.codeplex.com/ 微软企业库 现在已经到到6版本了 2013年更新的. https://www.microsoft.com/en-us/download/conf ...

  3. python爬虫小试

  4. 中国Linux开源镜像站大全

    本文来源:各大开源软件.发行版镜像页面.       请注意这是一个总结,如果您自己搭建了一个小型开源镜像,这里并没有.以下列出的是包含大量不同镜像的站点.       具体配置中,我建议您使用大企业 ...

  5. FlexPaper及二次开发

    Flexpaper二次开发入门教程 http://ajava.org/course/web/?page=2

  6. restful 注解 总结 (比较完整的):http://www.xuetimes.com/archives/388 , https://www.cnblogs.com/chen-lhx/p/5599806.html

    参考1:  http://www.xuetimes.com/archives/388 参考2:   https://www.cnblogs.com/chen-lhx/p/5599806.html 参考 ...

  7. HTML5 Canvas ( 事件交互, 点击事件为例 ) isPointInPath

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

  8. leetcode500

    public class Solution { public string[] FindWords(string[] words) { var list1 = new List<char> ...

  9. Declaration terminated incorrectly 讨厌 这样就不可以了

    #include "vcl.fctreeview.hpp"#include "RM_Class.hpp"#include "RM_Common.hpp ...

  10. Activity服务类-5 IdentityService服务类

    一.内置用户组(角色)设计表概念 用户和组(或者叫做角色),多对多关联,通过关联表实现 act_id_user 用户表: act_id_group 用户组表: act_id_membership 用户 ...