首页 > 代码库 > 文件增、删、改、查
文件增、删、改、查
查
1 while True: 2 l=[] 3 m=input("请输入您要查询的内容: ").strip() 4 flag=False 5 with open(‘haproxy.conf‘,‘r‘) as ha1: 6 for line in ha1: 7 if line.startswith("backend") and m in line: #第一步 定位到 backend行 8 flag=True 9 continue 10 if flag==True: #第二步 设置标志开关 11 l.append(line) 12 if line.startswith("backend") and flag: #第三步 跳出循环 13 break 14 for i in l: 15 print(i)
删除:
arg = {‘backend‘: ‘www.oldboy.org‘,‘record‘:{‘server‘:‘10.10.0.10 10.10.0.10‘,"weight":"9999", "maxconn": "33333333333"}} while True: choice = eval(input("请输入一个字典{}:").strip()) with open( "haproxy.conf",‘r‘) as a,open("b.txt",‘w‘) as b: for line in a: if line.startswith("backend") and choice["backend"] in line: continue if choice["record"][‘server‘] in line: continue else: b.write(line)
文件增、删、改、查
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。