def console_encode(string, errors='replace', stream=sys.__stdout__):
 encoding = _get_console_encoding(stream)
 if (PY3 and (encoding != 'UTF-8')):
  return string.encode(encoding, errors).decode(encoding)
 if (PY3 or IRONPYTHON):
  return string
 return string.encode(encoding, errors)

def console_encode ( string , errors = 'replace' , stream = sys . __stdout__ ) : encoding = _get_console_encoding ( stream ) if ( PY3 and ( encoding != 'UTF-8' ) ) : return string . encode ( encoding , errors ) . decode ( encoding ) if ( PY3 or IRONPYTHON ) : return string return string . encode ( encoding , errors )
encodes unicode to bytes in console or system encoding .