lundi 1 février 2016

How to for loop and check a condition such that the inner funtion is called one by one for each [on hold]

I have a python function say as follows :

for server in hostlist:
   if server.port not in safe_port_list:
       print "This is not a good server" 
       notify_subsystem(server.port,server.protocol,server.ip)
   else:
       print "whatever"

And lets say the notify_subsystem is a method which calls some external integration xyz.

The loop is simple and understandable i.e if the server port is not found in safe_port_list ,it will keep checking if condition for each host in one go.

I want something here which will call the notify_subsystem one by one and NOT in one go for all the servers.

   for server in hostlist:
   if server.port not in safe_port_list:
       print "This is not a good server" 
       `something_here`
         notify_subsystem(server.port,server.protocol,server.ip)
   else:
       print "whatever"

I am guessing i need a second loop at that place

Aucun commentaire:

Enregistrer un commentaire