Best way to delimit a list?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue May 13 06:51:06 EDT 2008
En Tue, 13 May 2008 07:28:03 -0300, <dannywebster at googlemail.com> escribió:
> Hi - I have a list returned from popen/readlines, and am wondering how
> to go about iterating over each item which was returned (rather than
> currently having the whole lot returned).
>
> so far:
>
>>>> f=os.open("./get_hostnames").readlines
>
> returns ['host1 host2 host3 ... hostN\n]'
You meant readlines(), I presume. A file acts as its own iterator:
f=os.open("./get_hostnames")
try:
for line in f:
# do something with line
finally:
f.close()
--
Gabriel Genellina
More information about the Python-list
mailing list