def is_binary(filename):
 try:
  return (not mimetypes.guess_type(filename)[0].startswith('text'))
 except AttributeError:
  return 1

def is_binary ( filename ) : try : return ( not mimetypes . guess_type ( filename ) [ 0 ] . startswith ( 'text' ) ) except AttributeError : return 1
file is binary if it contains a null-byte by default .