天天看點

python else語句和if語句的組合_python同時執行if和else語句

我的問題是python我們同時執行if和else語句

我試過“如果不是”,獨立于其他的,但似乎沒有任何效果。在

這是我劇本的一部分。我對這件事不太熟悉,是以我很感激你的幫助。在

我要做的是,如果cofig中有255.255.255.252,我要讀取。(這起作用了,并相應地改變了配置)但是如果沒有255.255.255.252,我的日志中應該有一個列印。在

結果是:(兩者兼而有之)

2017-10-26 15:39:29350 dailer 1關閉IP測試路由器完成

2017-10-26 15:39:29351 dailer 1 off IP lprm1212沒有/30for my_output in result0.split("\n"):

if len(my_output) !=0:

if my_output.find("255.255.255.252") != -1:

print (my_output)

tn.read_until('')

tn.write("config terminal"+"\n")

tn.read_until("(config)#")

tn.write("interface Dialer1"+"\n")

tn.read_until("(config-if)#")

tn.write("description test"+"\n")

tn.write("end"+"\n")

logger.debug('dailer 1 off IP ' + host2login + ' is completed')

else:

logger.debug('dailer 1 off IP ' + host2login + ' has no /30')

else:

logger.debug('dailer 1 off IP ' + host2login + ' has no /30')

else:

logger.debug('dailer 1 off IP ' + host2login + ' has no /30')