def detect_console_encoding():
 import locale
 global _initial_defencoding
 encoding = None
 try:
  encoding = (sys.stdout.encoding or sys.stdin.encoding)
 except AttributeError:
  pass
 if ((not encoding) or ('ascii' in encoding.lower())):
  try:
   encoding = locale.getpreferredencoding()
  except Exception:
   pass
 if ((not encoding) or ('ascii' in encoding.lower())):
  encoding = sys.getdefaultencoding()
 if (not _initial_defencoding):
  _initial_defencoding = sys.getdefaultencoding()
 return encoding

def detect_console_encoding ( ) : import locale global _initial_defencoding encoding = None try : encoding = ( sys . stdout . encoding or sys . stdin . encoding ) except AttributeError : pass if ( ( not encoding ) or ( 'ascii' in encoding . lower ( ) ) ) : try : encoding = locale . getpreferredencoding ( ) except Exception : pass if ( ( not encoding ) or ( 'ascii' in encoding . lower ( ) ) ) : encoding = sys . getdefaultencoding ( ) if ( not _initial_defencoding ) : _initial_defencoding = sys . getdefaultencoding ( ) return encoding
try to find the most capable encoding supported by the console .