一、eval函数复习:
a=[{'backend':'www.oldboy1.org','record':{'server':'2.2.2.4','weight':20,'maxconn':3000}},{'backend':'www.oldboy1.org','record':{'server':'2.2.2.5','weight':30,'maxconn':4000}}] print(type(a)) b={'backend':'www.oldboy1.org','record':{'server':'2.2.2.4','weight':20,'maxconn':3000}} # print(type(b)) c=[{'sdf':123,'ddd':'afdaf'}] # print(type(c)) d='[1,2,3]' print(type(d))
二、insert函数 的复习:
p=[123,'xyz'] p.insert(0,'abc') print(p)
三、write函数的复习:
filename = 'pragramming.txt' with open(filename,'w') as fileobject: #使用‘w’来提醒python用写入的方式打开 fileobject.write('I love your name!' ' I love your cloth!' ' I love your shoes!' ' I love your hair!') # 这种操作绝不会改动文件名的!!!! with open(filename,'a') as fileobject: #使用‘a’来提醒python用附加模式的方式打开 fileobject.write(' I an superman.')
四、查询功能:
1.题目:haproxy.conf文件内容如下:
global
log 127.0.0.1 local2
daemon
maxconn 256
log 127.0.0.1 local2 info
defaults
log global
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
option dontlognull
listen stats :8888
stats enable
stats uri /admin
stats auth admin:1234
frontend oldboy.org
bind 0.0.0.0:80
option httplog
option httpclose
option forwardfor
log global
acl www hdr_reg(host) -i www.oldboy.org
use_backend www.oldboy.org if www
backend www.oldboy1.org
server 101.1000.7.9 101.1000.7.9 weight 20 maxconn 30
server 2.2.2.7 2.2.2.7 weight 30 maxconn 4000
server 10.10.10.1 10.10.10.1 weight 22 maxconn 2000
server 2.2.2.4 2.2.2.4 weight 20 maxconn 3000
backend www.oldboy2.org
server 3.3.3.3 3.3.3.3 weight 20 maxconn 3000
backend www.oldboy20.org
server 10.10.0.10 10.10.0.10 weight 9999 maxconn 33333333333
2.查询功能要求与代码:
# 题目要求: # 对于查询,输入backend 后面 的网址,就查出来server相关的内容 # 对于修改,必须是查到的情况下进行修改操作,如果没有查询到,修改个P # 修改要求:将haproxy中的backend www.oldboy1.org下面的server 2.2.2.4 2.2.2.4 weight 20 maxconn 3000 # 改成:server 2.2.2.5 2.2.2.5 weight 30 maxconn 4000 def fetch(data): #因为是查询功能,所以必须需要调用一个参数 # print(' 33[1;43m这是查询功能 33[0m') # print(' 33[1;43m用户输入的数据是 33[0m',data) backend_data='backend %s' %data with open('haproxy.conf','r') as read_f: tag=False ret=[] for read_line in read_f: if read_line.strip()==backend_data: tag=True continue if tag and read_line.startswith('backend'): break #后面有return,因此这里先放一个break if tag: #这时,tag为ture状态 print('