[Tutor] Newbie with question about readfiles()
Remco Gerlich
scarblac@pino.selwerd.nl
Thu, 25 Apr 2002 22:06:32 +0200
On 0, 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 ???
in_file = open("foo.txt", "r")
lines = in_file.readlines() # lines is a list with all lines now
print lines[7] # print the 8th line (Python counts from 0)
--
Remco Gerlich