再不冒泡,担心被吾爱开除
不说废话,直接上代码
抛砖引玉,有请大神献上更优雅方法
[Python] 纯文本查看 复制代码import time
ip_list = ['ip1', 'ip2', 'ip3']
ip_iter = iter(ip_list)
IP = next(ip_iter)
while True:
try:
print(IP)
d = "a" + 1 # 故意设置的出错代码
time.sleep(1)
except:
print('IP出错, 使用下一个IP地址')
if IP == ip_list[-1]:
ip_iter = iter(ip_list)
IP = next(ip_iter)
else:
IP = next(ip_iter)
print(IP)
time.sleep(1)