code: def tail_of_file(filename, n, ansi2html=False):
      
      avg_line_length = 74
      to_read = n
  
      with open(filename) as f:
          while 1:
              try:
                  f.seek(-(avg_line_length * to_read), 2)
              except IOError:
                  # woops.  apparently file is smaller than what we want
                  # to step back, go to the beginning instead
                  f.seek(0)
              pos = f.tell()
              lines = f.read().splitlines()
              if len(lines) >= to_read or pos == 0:
                  if ansi2html:
                      return convertAnsi2html('\n'.join(lines[-to_read:]))
                  return '\n'.join(lines[-to_read:]) + '\n'
              avg_line_length *= 1.3
docs: Reads a n lines from f with an offset of offset lines.