iterating over a list and printing
Bart Nessux
bart_nessux at hotmail.com
Wed Feb 11 11:12:25 EST 2004
Richie Hindle wrote:
> [Bart]
>
>>>>ip_list.append(inputFile.read())
>
>
> You probably meant something like this (untested):
>
> inputFile = file('ips.txt', 'r')
> ip_list = inputFile.readlines() # Note readlines() rather than read()
> inputFile.close()
> for i in ip_list:
> print "/sbin/ifconfig %s netmask 255.255.252.0 broadcast 128.173.123.255 up" %i
>
> If you really do need to create ip_list up front and append to it,
> you should use extend() rather than append() - see the "mutable
> sequence types" documentation for details.
>
Thanks to everyone for the replies. This works now.
More information about the Python-list
mailing list