Re: iterating over a list and printing
From: Richie Hindle (richie_at_entrian.com)
Date: 02/11/04
- Next message: Richie Hindle: "Re: How to avoid "f.close" (no parens) bug?"
- Previous message: Batista, Facundo: "RE: How to avoid "f.close" (no parens) bug?"
- In reply to: Bart Nessux: "iterating over a list and printing"
- Next in thread: Bart Nessux: "Re: iterating over a list and printing"
- Reply: Bart Nessux: "Re: iterating over a list and printing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 11 Feb 2004 15:41:22 +0000 To: python-list@python.org
[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.
-- Richie Hindle richie@entrian.com
- Next message: Richie Hindle: "Re: How to avoid "f.close" (no parens) bug?"
- Previous message: Batista, Facundo: "RE: How to avoid "f.close" (no parens) bug?"
- In reply to: Bart Nessux: "iterating over a list and printing"
- Next in thread: Bart Nessux: "Re: iterating over a list and printing"
- Reply: Bart Nessux: "Re: iterating over a list and printing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]