REALLY need help with iterating a list.
fredrik at pythonware.com
Mon Jun 11 21:23:28 CEST 2007
> How about something like this?
> while serverlist:
> server = serverlist.pop(0)
> pinger = ping[server]
> if pinger.returncode==None:
> pingresult[server] = pinger.stdout.read()
> pingreturncode[server] = pinger.returncode
> Basic idea: as long as there are servers in the list, pop the first
> one out of the list, see if it's done, and if it isn't, put it back on
> the end of the list.
here's a simple variation of that, which is a bit more efficient, and
perhaps also a bit easier to use in the general case:
still_active = 
for server in serverlist:
pinger = ping[server]
if pinger.returncode is None:
pingresult[server] = pinger.stdout.read()
pingreturncode[server] = pinger.returncode
serverlist = still_active
More information about the Python-list