iterating over a list and printing

Bart Nessux bart_nessux at
Wed Feb 11 17:12:25 CET 2004

Richie Hindle wrote:
> [Bart]
> 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 broadcast 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