| | |
how do i read the last line of a text file?
Thread Solved |
Use readlines() to get a list of lines ...
python Syntax (Toggle Plain Text)
# read a text file as a list of lines # find the last line, change to a file you have fileHandle = open ( 'test3.txt',"r" ) lineList = fileHandle.readlines() fileHandle.close() print lineList print "The last line is:" print lineList[len(lineList)-1] # or simply print lineList[-1]
Last edited by vegaseat; Aug 12th, 2009 at 12:51 pm.
May 'the Google' be with you!
![]() |
Similar Threads
- Read comma separated data from a text file (C)
- read from database and writing the contents into a text file (C)
- Help with a 2D array from a text file (C++)
- Reading in a text file string is not complete (Pascal and Delphi)
- help on using StringTokenizer to read and compute multiple lines from text (Java)
- 10 line text file (Java)
Other Threads in the Python Forum
- Previous Thread: simple cgi script issue
- Next Thread: My Irritating Error - Help
| Thread Tools | Search this Thread |
abrupt alarm ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error exe file float format function generator getvalue gnu graphics halp heads homework http ideas import input itunes java leftmouse line linux list lists loop maze module mouse number numbers output parsing path pointer prime programming progressbar push py2exe pygame python random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh statistics string strings sudokusolver sum table terminal text thread threading time tlapse tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo vigenere web webservice wikipedia write wxpython xlib






