Module:utils.encoding
Utilities for dealing with text encodings
2 Functions
- IPython.utils.encoding.get_stream_enc(stream:Any,default:str|None=None)→str|None
Return the given stream’s encoding or a default.
There are cases where
sys.std*might not actually be a stream, socheck for the encoding attribute prior to returning it, and returna default if it doesn’t exist or evaluates as False.defaultis None if not provided.
- IPython.utils.encoding.getdefaultencoding(prefer_stream:object|bool=<objectobject>)→str
Return IPython’s guess for the default encoding for bytes as text.
If prefer_stream is True (default), asks for stdin.encoding first,to match the calling Terminal, but that is often None for subprocesses.
Then fall back on locale.getpreferredencoding(),which should be a sensible platform default (that respects LANG environment),and finally to sys.getdefaultencoding() which is the most conservative option,and usually UTF8 as of Python 3.