#NEWLINE# def tail( the_file , lines_2find = 20 ) : #NEWLINE# #INDENT# '\n    From http://stackoverflow.com/questions/136168/get-last-n-lines-of-a-file-with-python-similar-to-tail\n    ' #NEWLINE# the_file . seek ( 0 , 2 ) #NEWLINE# bytes_in_file = the_file . tell ( ) #NEWLINE# ( lines_found , total_bytes_scanned ) = ( 0 , 0 ) #NEWLINE# while ( ( ( lines_2find + 1 ) > lines_found ) and ( bytes_in_file > total_bytes_scanned ) ) : #NEWLINE# #INDENT# byte_block = min ( 1024 , ( bytes_in_file - byte_block ) ) #NEWLINE# the_file . seek ( ( - ( byte_block + total_bytes_scanned ) ) , 2 ) #NEWLINE# total_bytes_scanned += byte_block #NEWLINE# lines_found += the_file . read ( 1024 ) . count ( '\n' ) #NEWLINE# #UNINDENT# the_file . seek ( ( - total_bytes_scanned ) , 2 ) #NEWLINE# line_list = list ( the_file . readlines ( ) ) #NEWLINE# return line_list [ ( - lines_2find ) : ]