04-09,Work-对文件的增删改查(函数)

Posted 高卓

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了04-09,Work-对文件的增删改查(函数)相关的知识,希望对你有一定的参考价值。

#增删改查之查
def look():
while 1 :
enter = input("查看:如www.oldboy.org\n")
l = []
flag = False
with open("haproxy.conf") as enter_read:
for line in enter_read:
if line.startswith("backend") and enter in line:
flag = True
continue
if line.startswith("backend") and flag:
break
if flag:
l.append(line.strip())
for out in l:
print(out)
#增删改查之删
def delete():
dels = input("删除:如www.oldboy.org\n")
with open("haproxy.conf") as dels_read,open("text",mode="w") as dels_del:
for line in dels_read:
dels_del.write(line)
if line.startswith("backend") and dels in line:
break
#增删改查之改
def amend():
modify = input("修改:如www.oldboy.org\n")
servers = " server 1111 weight 2222 maxconn 3333"
with open("haproxy.conf") as modify_read,open("text",mode="w") as modify_m:
for line in modify_read:
modify_m.write(line)
if line.startswith("backend") and modify in line:
modify_m.write(servers)
break
#增删改查之增
def add():
agg = input("增加:如www.oldboy.org\n")
servers = " server 1111 weight 2222 maxconn 3333\n"
with open("haproxy.conf") as agg_read, open("text", mode="w") as agg_a:
for line in agg_read:
agg_a.write(line)
if line.startswith("backend") and agg in line:
agg_a.write(servers)

#列表
def list():
user_list = ‘‘‘
1.look 查看:
2.delete 删除:
3.amend 修改:
4.add 增加:
0.exit 退出:
‘‘‘
print(user_list)

def mains():
list()
judge = input("弄什么:")
if judge==1:
look()
if judge==2:
delete()
if judge==3:
amend()
if judge==4:
add()
if judge==0:
exit()
mains()

以上是关于04-09,Work-对文件的增删改查(函数)的主要内容,如果未能解决你的问题,请参考以下文章

数据库的增删改查?

mybatis生成的增删改查怎么用

怎样快速学会mysql的增删查改

java web 就是对数据库的增删改查么

vue简单的增删查

java中的增删改查的一些小问题