IPython Documentation

Table Of Contents

Previous topic

utils.doctestreload

Next topic

utils.frame

This Page

utils.encoding

Module: utils.encoding

Utilities for dealing with text encodings

Functions

IPython.utils.encoding.get_stream_enc(stream, default=None)

Return the given stream’s encoding or a default.

There are cases where sys.std* might not actually be a stream, so check for the encoding attribute prior to returning it, and return a default if it doesn’t exist or evaluates as False. `default’ is None if not provided.

IPython.utils.encoding.getdefaultencoding()

Return IPython’s guess for the default encoding for bytes as text.

Asks for stdin.encoding first, to match the calling Terminal, but that is often None for subprocesses. 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 ASCII.