iterating over a list and printing
fidtz at clara#spam#.co.uk
Wed Feb 11 16:36:23 CET 2004
"Bart Nessux" <bart_nessux at hotmail.com> wrote in message
news:c0dhev$2gp$1 at solaris.cc.vt.edu...
> ip_list = 
> inputFile = file('ips.txt', 'r')
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.
> for i in ip_list:
> print "/sbin/ifconfig %s netmask 255.255.252.0 broadcast
> 126.96.36.199 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 188.8.131.52 up). Any ideas on how to fix this? The
> results are to print a line for each IP.
> /sbin/ifconfig IP1 netmask 255.255.252.0 broadcast 184.108.40.206 up
> /sbin/ifconfig IP2 netmask 255.255.252.0 broadcast 220.127.116.11 up
More information about the Python-list