def tailLines(filename, linesback):
 avgcharsperline = 150
 file = open(filename, 'r')
 while 1:
  try:
   file.seek((((-1) * avgcharsperline) * linesback), 2)
  except IOError:
   file.seek(0)
  if (file.tell() == 0):
   atstart = 1
  else:
   atstart = 0
  lines = file.read().split('\n')
  if ((len(lines) > (linesback + 1)) or atstart):
   break
  avgcharsperline = (avgcharsperline * 1.3)
 file.close()
 if (len(lines) > linesback):
  start = ((len(lines) - linesback) - 1)
 else:
  start = 0
 return lines[start:(len(lines) - 1)]

def tailLines ( filename , linesback ) : avgcharsperline = 150 file = open ( filename , 'r' ) while 1 : try : file . seek ( ( ( ( - 1 ) * avgcharsperline ) * linesback ) , 2 ) except IOError : file . seek ( 0 ) if ( file . tell ( ) == 0 ) : atstart = 1 else : atstart = 0 lines = file . read ( ) . split ( '\n' ) if ( ( len ( lines ) > ( linesback + 1 ) ) or atstart ) : break avgcharsperline = ( avgcharsperline * 1.3 ) file . close ( ) if ( len ( lines ) > linesback ) : start = ( ( len ( lines ) - linesback ) - 1 ) else : start = 0 return lines [ start : ( len ( lines ) - 1 ) ]
python tail - modified from recipe at URL returns list of [linesback] lines from end of [filename] .