Re: iterating over a list and printing
From: vincent wehren (vincent_at_visualtrans.de)
Date: 02/11/04
- Next message: Peter Otten: "Re: iterating over a list and printing"
- Previous message: Joe Richett: "HowTo exec every line of a file inside python program"
- In reply to: Bart Nessux: "iterating over a list and printing"
- Next in thread: Peter Otten: "Re: iterating over a list and printing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 11 Feb 2004 16:39:12 +0100
"Bart Nessux" <bart_nessux@hotmail.com> schrieb im Newsbeitrag
news:c0dhev$2gp$1@solaris.cc.vt.edu...
| ip_list = []
| inputFile = file('ips.txt', 'r')
| ip_list.append(inputFile.read())
You just added the entire contents as a single element to ip_list
To iterate over the indiviual lines, you should go
for i in file("ips.txt"):
print "/sbin/ifconfig %s netmask 255.255.252.0 broadcast 128.173.123.255
up" %i
HTH,
Vincent Wehren
| inputFile.close()
| for i in ip_list:
| print "/sbin/ifconfig %s netmask 255.255.252.0 broadcast
| 128.173.123.255 up" %i
|
| The last line does not work. It prints the first part (/sbin/ifconfig),
| then the entire list of ips, then the second part (netmask 255.255.252.0
| broadcast 128.173.123.255 up). Any ideas on how to fix this? The desired
| results are to print a line for each IP.
|
| /sbin/ifconfig IP1 netmask 255.255.252.0 broadcast 128.173.123.255 up
| /sbin/ifconfig IP2 netmask 255.255.252.0 broadcast 128.173.123.255 up
| etc...
|
- Next message: Peter Otten: "Re: iterating over a list and printing"
- Previous message: Joe Richett: "HowTo exec every line of a file inside python program"
- In reply to: Bart Nessux: "iterating over a list and printing"
- Next in thread: Peter Otten: "Re: iterating over a list and printing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|