def file_requires_unicode(x):
 try:
  x.write('')
 except TypeError:
  return True
 else:
  return False

def file_requires_unicode ( x ) : try : x . write ( '' ) except TypeError : return True else : return False
returns true if the given writable file-like object requires unicode to be written to it .