[Tutor] Newbie with question about readfiles()
Kojo Idrissa
kojo@hal-pc.org
Thu, 25 Apr 2002 15:15:42 -0500
--=====================_24377332==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed
Use readline() instead of readlines(). The first reads lines one at a
time The second reads all the lines in a file.
Then just add a counter that starts 0. When it gets to 7, print that line.
At 03:19 PM 4/25/2002 -0400, stuart_clemons@us.ibm.com wrote:
>Hi all:
>
>Just wondering how I would print only a given line in a text file. For
>example, I would like to print the 8th line in this multi-line file, foo.txt.
>
>in_file = open ("foo.txt", "r")
>for line in in_file.readlines():
>print line# I know this prints all lines
>print ????# How do I print line 8 only ???
>
>
>Thanks,
>
>Stuart, the Python newbie
****************************
Kojo Idrissa
kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************
--=====================_24377332==_.ALT
Content-Type: text/html; charset="us-ascii"
<html>
Use readline<b>() </b>instead of readline<b><i>s</i></b>(). The
first reads lines one at a time The second reads all the lines in a
file.<br><br>
Then just add a counter that starts 0. When it gets to 7, print
that line.<br><br>
At 03:19 PM 4/25/2002 -0400, stuart_clemons@us.ibm.com wrote:<br><br>
<blockquote type=cite class=cite cite>Hi all:<br><br>
Just wondering how I would print only a given line in a text file. For
example, I would like to print the 8th line in this multi-line file,
foo.txt.<br><br>
in_file = open ("foo.txt", "r")<br>
for line in in_file.readlines():<br>
print line# I know this prints all lines<br>
print ????# How do I print line 8 only ???<br><br>
<br>
Thanks,<br><br>
Stuart, the Python newbie </blockquote>
<x-sigsep><p></x-sigsep>
**************************** <br>
Kojo Idrissa <br>
<br>
kojo@hal-pc.org<br>
<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">http://www.hal-pc.org/~kojo/<br>
</a>****************************</html>
--=====================_24377332==_.ALT--