Newbie: need help with control loop
Terry Reedy
tjreedy at udel.edu
Mon Dec 13 00:49:18 EST 1999
In article <38543b80.289200819 at news-server>,
nospam.python at scoobysnacks.com says...
>
>I'm trying to write a simple program to change passwords on a large
>number of routers but I'm having trouble with the control loop. This
>may be very poor code but I've only been at this for a week. I want
>to do more than one router at a time so I don't have to wait for each
>one to finish before I start the next. I also don't want to start ALL
>of them at the same time. The problem I'm having is being able to
>create an object instance based on a list value. The list is
>arbitrary and may change often. Here is where I'm at.
>
>if __name__ == '__main__':
> list=['host1','host2','host3','host4','host5',
> 'host6','host7','host8','host9','host0']
'list' is the name of a built in function, and therefor a bad choice of
local variable name. Use 'hosts' instead
> running=[]
> for machine in range(len(list)):
You do not appear to need index. If not, better is
for machine in hosts:
You should probable create instance next:
host_inst = class_name(machine)
> running = running + [list[machine]]
running.append(host_inst) # does not copy list, merely adds
> """I want right here to create a class instance
> based on list[machine] and have it begin
>
> ?? list[machine]=testclass() ?? """
See above
>
> while len(running) >= 4 : # no more than 4 working
>
> for currentitem in range(len(running)):
here you will want index (for deletion)
> #
> # kill if done
instance = running[currentitem]
> # if instance.status == ('done') :
> #del instance
del running[currentitem]
> print running[currentitem],
>
> del running[0]
This makes no sense. Will not be done.
> print ''
> #loop to finish anything remaining in running[]
>
>Any and all help appreciated.
TJR
PS. If you want an email copy of responses, give us a real address.
More information about the Python-list
mailing list