[Tutor] Newbie with question about readfiles()

stuart_clemons@us.ibm.com stuart_clemons@us.ibm.com
Thu, 25 Apr 2002 15:19:49 -0400


--0__=0ABBE135DFFA09A38f9e8a93df938690918c0ABBE135DFFA09A3
Content-type: text/plain; charset=US-ASCII

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
--0__=0ABBE135DFFA09A38f9e8a93df938690918c0ABBE135DFFA09A3
Content-type: text/html; charset=US-ASCII
Content-Disposition: inline

<html><body>
<p>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 (&quot;foo.txt&quot;, &quot;r&quot;)<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</body></html>
--0__=0ABBE135DFFA09A38f9e8a93df938690918c0ABBE135DFFA09A3--