def select_best_encoding(outstream=None):
 outstream = (outstream or sys.stdout)
 encoding = (getattr(outstream, 'encoding', None) or sys.getdefaultencoding())
 if is_ascii_encoding(encoding):
  return 'utf-8'
 return encoding

def select_best_encoding ( outstream = None ) : outstream = ( outstream or sys . stdout ) encoding = ( getattr ( outstream , 'encoding' , None ) or sys . getdefaultencoding ( ) ) if is_ascii_encoding ( encoding ) : return 'utf-8' return encoding
select the *best* encoding for an output stream/file .