1. 程式人生 > >查詢功能

查詢功能

clas div 輸入 str delete 循環 int 刪除 tag

 1 tag = True
 2 while tag:
 3     # print(‘請輸入:1\n2\n3\n4\n‘)
 4     if tag:
 5         print(level)
 6         choice = input(請輸入:)
 7         if choice==quit:
 8             break
 9         elif choice==quit_all:
10             tag = False
11         while tag:
12             print(level2
) 13 choice = input(請輸入:) 14 if choice == quit: 15 break 16 elif choice == quit_all: 17 tag = False 18 while tag: 19 print(level3) 20 choice = input(請輸入:) 21 if choice ==
quit: 22 break 23 elif choice == quit_all: 24 tag = False 25 26 def fetch(data): 27 print(這是查詢到的內容) 28 # print(‘%s這是要查詢的數據‘ %data) 29 backend_data = backend %s %data 30 with open(haproxy.conf,r) as read_f: 31 tag = False
32 for read_line in read_f: 33 if read_line.strip() == backend_data: 34 tag = True #如果輸入內容和查找到的內容相同改變tag狀態並重新循環 35 continue 36 if tag and read_line.startswith(backend): 37 break #如果遇到了下一個backend,終止循環 38 if tag: 39 print(read_line,end=‘‘) #一條一條打印,打印到break出現為止 40 41 def add(): 42 print(這是添加) 43 44 def change(): 45 print(這是更改) 46 47 def delete(): 48 print(這是刪除) 49 50 if __name__ == __main__: 51 msg=‘‘‘ 52 1:查詢 53 2:添加 54 3:修改 55 4:刪除 56 5:退出 57 ‘‘‘ 58 msg_dic = { 59 1:fetch, 60 2:add, 61 3:change, 62 4:delete 63 } 64 while True: 65 print(msg) 66 choice = input(請輸入:).strip() 67 if not choice:continue #如果用戶沒有輸入內容則重新循環 68 if choice == 5:break 69 data = input(請輸入要查詢的內容) 70 msg_dic[choice](data) #假如用戶輸入的是‘1‘,那麽就變成msg_dic[1]() == fetch()函數

查詢功能