how do i read the last line of a text file?

Thread Solved

Join Date: May 2005
Posts: 8
Reputation: ruwach is an unknown quantity at this point 
Solved Threads: 0
ruwach ruwach is offline Offline
Newbie Poster

how do i read the last line of a text file?

 
0
  #1
May 29th, 2005
Hey there.
i want to set a variable to represent the last line of a text file
how do i do that?
or even better, how do i create a list of the lines of a text file?
any suggestions?
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,947
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 914
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: how do i read the last line of a text file?

 
0
  #2
May 29th, 2005
Use readlines() to get a list of lines ...
  1. # read a text file as a list of lines
  2. # find the last line, change to a file you have
  3. fileHandle = open ( 'test3.txt',"r" )
  4. lineList = fileHandle.readlines()
  5. fileHandle.close()
  6. print lineList
  7. print "The last line is:"
  8. print lineList[len(lineList)-1]
  9. # or simply
  10. print lineList[-1]
Last edited by vegaseat; Aug 12th, 2009 at 12:51 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 8
Reputation: ruwach is an unknown quantity at this point 
Solved Threads: 0
ruwach ruwach is offline Offline
Newbie Poster

Re: how do i read the last line of a text file?

 
0
  #3
May 29th, 2005
Great !
Works great.
You know, you are the one who helped me with my last problem.
thanks a whole lot.
you are making my life easier.
:cheesy:
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC