how to list elements line by line?
John Hunter
jdhunter at nitace.bsd.uchicago.edu
Fri May 17 17:34:10 EDT 2002
>>>>> "magni2k" == magni2k <magni2k at uni.de> writes:
magni2k> Hi, I have a problem. How can I list all the elements in
magni2k> my serverlist.txt seperate. That means line by line! So
magni2k> that I can call for example: List only the Hostnames! And
magni2k> on the other hand that I can call for example: List
magni2k> only the 1st Hostname, then the 2nd and so on! (If its
magni2k> possible with the sys.argv argument!) Anybody an idea
# This lists the lines one by one
fh = open('somefile.txt')
for line in fh.readlines():
print line,
# This prints the 3rd line
lines = open('somefile.txt').readlines()
print lines[2]
For the record, the syntactical element to end sentences in English is
the period.
Tschuss,
John Hunter
More information about the Python-list
mailing list