iterating over a list and printing

DomF fidtz at
Wed Feb 11 16:36:23 CET 2004

"Bart Nessux" <bart_nessux at> wrote in message
news:c0dhev$2gp$1 at
> ip_list = []
> inputFile = file('ips.txt', 'r')
> ip_list.append(

This line just reads the whole file into the first element of the list.
Put "print ip_list" here to confirm this to yourself.

You need to loop over the file with the optional "size" parameter set or
by using inputFile.readlines() if ips.txt is one IP address per line.


> inputFile.close()
> for i in ip_list:
>     print "/sbin/ifconfig %s netmask broadcast
> up" %i
> The last line does not work. It prints the first part
> then the entire list of ips, then the second part (netmask
> broadcast up). Any ideas on how to fix this? The
> results are to print a line for each IP.
> /sbin/ifconfig IP1 netmask broadcast up
> /sbin/ifconfig IP2 netmask broadcast up
> etc...

More information about the Python-list mailing list