code: def file_empty(fp):
      
      # for python 2 we need to use a homemade peek()
      if six.PY2:
          contents = fp.read()
          fp.seek(0)
          return not bool(contents)
  
      else:
          return not fp.peek()
docs: Determine if a file is empty or not.