码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-04-09 20:33:01      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:backend   bre   tin   proxy   false   org   line   退出   []   

#增删改查之查
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-对文件的增删改查(函数)

标签:backend   bre   tin   proxy   false   org   line   退出   []   

原文地址:http://www.cnblogs.com/gz369521/p/6686028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!