parameters: ()
return_statement: return encoding
docstring: Try to find the most capable encoding supported by the console.
      slightly modified from the way IPython handles the same issue.
docstring_summary: Try to find the most capable encoding supported by the console.
      slightly modified from the way IPython handles the same issue.
docstring_tokens: Try to find the most capable encoding supported by the console . slightly modified from the way IPython handles the same issue .
function: def detect_console_encoding():
      """
      Try to find the most capable encoding supported by the console.
      slightly modified from the way IPython handles the same issue.
      """
      global _initial_defencoding
  
      encoding = None
      try:
          encoding = sys.stdout.encoding or sys.stdin.encoding
      except (AttributeError, IOError):
          pass
  
      # try again for something better
      if not encoding or "ascii" in encoding.lower():
          try:
              encoding = locale.getpreferredencoding()
          except locale.Error:
              # can be raised by locale.setlocale(), which is
              #  called by getpreferredencoding
              #  (on some systems, see stdlib locale docs)
              pass
  
      # when all else fails. this will usually be "ascii"
      if not encoding or "ascii" in encoding.lower():
          encoding = sys.getdefaultencoding()
  
      # GH#3360, save the reported defencoding at import time
      # MPL backends may change it. Make available for debugging.
      if not _initial_defencoding:
          _initial_defencoding = sys.getdefaultencoding()
  
      return encoding
function_tokens: def detect_console_encoding ( ) : global _initial_defencoding encoding = None try : encoding = sys . stdout . encoding or sys . stdin . encoding except ( AttributeError , IOError ) : pass # try again for something better if not encoding or "ascii" in encoding . lower ( ) : try : encoding = locale . getpreferredencoding ( ) except locale . Error : # can be raised by locale.setlocale(), which is #  called by getpreferredencoding #  (on some systems, see stdlib locale docs) pass # when all else fails. this will usually be "ascii" if not encoding or "ascii" in encoding . lower ( ) : encoding = sys . getdefaultencoding ( ) # GH#3360, save the reported defencoding at import time # MPL backends may change it. Make available for debugging. if not _initial_defencoding : _initial_defencoding = sys . getdefaultencoding ( ) return encoding