文件的解耦
函数编程+文件处理+tag的用法+程序解耦
1 import os 2 3 def file_handler(backend_data, res=None, type='fetch'): 4 if type == 'fetch': 5 with open('haproxy.conf', 'r') as read_f: 6 tag = False 7 ret = [] 8 for read_line in read_f: 9 if read_line.strip() == backend_data: 10 tag = True 11 continue 12 if tag and read_line.startswith('backend'): 13 # tag=False 14 break 15 if tag: 16 print('